Quitting Cigarettes with Vaping

I have smoked cigarettes for 25 years. For the past about 4 years I have been saying i’m going to quit but I could never really do it. I smoked about a pack to a pack and a half a day.  About 10 years ago I was at a kiosk in the mall and there were electronic cigarettes there and my brother and I both purchased them. We used them and then when they were done we went right back to cigarettes.  So about a 2 months ago i seen that they had something called Vuse Vibe so i bought one. It kept me from smoking the whole time that i was vaping with it. It was rather expensive so i decided to go out to a vaping store and get a vaping unit and e-juices to go along with it.

It has been almost 2 months and I have smoked about 5 packs of cigarettes in that 2 months (usually when i’m out drinking beer).  Vaping has really made it possible for me to quit smoking.  I have read a report that people who vape have all most no cancer causing carcinogens in their system compared to people that smoke.  I’m getting old so taking care of my health is becoming more and more of a priority.  Just wanted to put it out there that vaping is a reasonable route to quit smoking. Not just for me, i’ve seen other people who have quit smoking by vaping. Right now I have a kangertech toptank evod system and 1 coil costs 1.50 and i spend about 14 dollars on juice a week. I could probably get those numbers down a bit more but i don’t plan on vaping for the rest of my life.  Eventually when I get enough time without smoking and only vaping then i’m going to cut down on vaping.

So I just wanted to put that out there that vaping IS an alternative to smoking and it has worked very well for me and plenty of other people. It is way cheaper than smoking and a lot healthier for you as well. If you vape to stop smoking I say keep up the good work.  A lot of people joke about people who vape but it is really a good way to quit cigarettes. Thank you for reading I hope that this article may help another smoker who is really addicted to nicotine and is helpless over the addiction how I once was.

Having a Smartphone in Class

Whether you think it is a good idea or a bad idea students are going to have cell phones in class for as long as cell phones exist. To be honest every time I go to class I put my cell phones sound settings on silent and I don’t use my cellphone unless instructed by the professor to do so. I think having a smart phone in class is a good idea for those occasions where the professor tells the class to “Google” something. Also, smart phones are an important device for emergency use so I personally cannot see any type of rule to abolish use of smart phones in class. But there are the occasions where students have their ringers on and interrupt class in the middle of a lecture with a very loud ringing of their smart phone. I have seen a teacher get really mad at a student for his phone ringing in class when it was even past the end of class time.

All in all I think that having a smart phone in class is a good idea. At the end of class you can get contacts of classmates and make new friends, use the smart phone to “Google” something if the teacher permits it, and most importantly in the case of an emergency you have your smart phone. All that I can really come up with are positive reasons to having a smart phone in class compared to the very minor negative effects of smart phones in class which are usually only committed by people who aren’t serious about being a student in the first place.

Everyone has a smart phone these days and they are a very usefull source of information. Students need information more than anyone these days to stay on top of their game. Whether it be reviewing classwork over the net to getting a new contact, to even emergency use, smart phones are going to be a part of our everyday lives for a very long time. Thank you for reading 🙂

 

Naked Man Space Suit

So, I have always wondered how people will be able to expand into space and colonize other planets. It occurred to me that we will need to be able to enter outer space without space suits. Yep that’s it!! We will have to find some way to shield our skin and all our holes(nostrils, mouth, etc….) so that if we were in outer space, or some other planets surface we will survive without almost dying instantly.

Lately I have heard of “water bears” or (tardigrades) and supposedly they can withstand temperatures ranging from -272 deg C to +150 deg C, they can be without water for a period of 10 years, and they are extremely resistant to radiation. Now if you ask me the scientists should have jumped on that discovery since they first made it and figured out some way to blend that organisms homeostatic properties with that of the human being.  Its always been a dream of mine to be able to live in space without a spacesuit and maybe these water bears are the key.

Not only does copypasteearth think that eventually there will be an actual earth for each and every person, they love to think about floating through space naked haha. We have come a long way into exploration of space and personally I think that if we have any chance at all of colonizing Mars we will definitely need a Naked Man Space Suit. There would maybe have to be some biological engineering going on between the tardigrades and the humans so that we can have the same resistance in space that they do. Our nostrils, mouth, anus, and other openings would have to have some sort of transparency to the genetic mutation so we can still use them. If NASA or SpaceX is working on something like this my hats off to them. Probably not in my life time but I forsee the naked man spacesuit in the future of mankind. Thank you for reading 😉

How to work with JSON (JavaScript Object Notation)

In this article I will write about working with JSON. JSON stands for JavaScript Object Notation. It is a great way to send objects back and forth through client-server and also to create API’s that return JSON when information is requested. Lets look at an object in javascript.


var object = {
self : {name:"customer1",job:"cashier"},
todo :"jsonobject",
names : [{employ:"work",happy:true,work:"program"},
{employ:"job",happy:false,work:"intro"}]
};

This object, called object has a couple variables and an array names. Now lets see this object in JSON format.


{"self":{"name":"customer1","job":"cashier"},
"todo":"jsonobject",
"names":[{"employ":"work","happy":true,"work":"program"},
{"employ":"job","happy":false,"work":"intro"}]}

in javascript to turn an object into JSON you use the JSON.Stringify method

JSON.stringify(object);

And to turn JSON into and Object you use JSON.Parse method


var object = JSON.parse(json);

Now to work with JSON in php you can make objects in php and then use json_encode to turn the object into JSON like this


<?php $myObj = new \stdClass();
$myObj->name = "John";
$myObj->age = 30;
$myObj->city = "New York";
$myArray = array();
for($i = 0;$i < 10;$i++){ 
$myArray[$i] ="hello world".$i; 
} 
$myObj->hello = $myArray;
$myJSON = json_encode($myObj);
echo $myJSON;
?>

Now the variable $myJSON will look like this after you encode it


{"name":"John",
"age":30,
"city":"New York",
"hello":["hello world0","hello world1",
"hello world2","hello world3","hello world4",
"hello world5","hello world6","hello world7",
"hello world8","hello world9"]}

and if you are sending a JSON object to a php script using JSON.stringify you can grab the object in php with something like this using json-decode

$obj = json_decode($_POST["x"], false);

And that is pretty much the basics for using JSON in javascript and php. One note i was looking around and it appears that you are not supposed to send functions through JSON but there is a way that is not consistent so it shouldnt actually be done, as far as i know. I hope you enjoyed this article. Untill next time 🙂

A Cookie Helper object in JavaScript

This example is a little helper class to make and erase cookies in javascript. I will first post the Cookies.js script that will create, read, and erase cookies from your browser.

Cookies.js


/*
author: Copypasteearth 7/17/2017
*/

function COOKIE () {

this.createCookie = function (name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
,
this.readCookie = function (name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
,
this.eraseCookie = function(name) {
this.createCookie(name,"",-1);
}
}

Then you just include this javascript in a webpage and create the object and then you can call the different functions as you will. Here is an example HTML file using it. This file just pretty much tests out the Cookies.js file.

index.html


<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8" />
<title>profile</title>
</head>

<body>

<script src="Cookies.js"></script>
<h1>this is a test of Cookies</h1>
<h2 id = "cook"></h2>
<input id = "cookiename" type="text" placeholder="cookie name..."></input>
<input id = "cookievalue" type="text" placeholder="cookie value..."></input>
<input id = "days" type = "number" placeholder="number of days"></input>
<button onclick="buttonClick()">Create Cookie</button>
<br>
<input id = "getcookie" placeholder="cookie name"></input>
<button onclick="getCookie()">Read Cookie</button>
<br>
<input id = "erase" placeholder="cookie name"></input>
<button onclick="deleteCookie()">Erase Cookie</button>
<p id= "paragraph"></p>
<script>
var Cookie = new COOKIE();
function buttonClick(){
var name = document.getElementById("cookiename").value;
var value = document.getElementById("cookievalue").value;
var days = document.getElementById("days").value;
Cookie.createCookie(name,value,days);
document.getElementById("paragraph").innerText = "Cookie Created: " + name + "=" + value + ";" + days;
}
function getCookie(){
var name = document.getElementById("getcookie").value;
var cookie = Cookie.readCookie(name);
document.getElementById("paragraph").innerText = "Cookie Read: " + name + "=" + cookie;
}
function deleteCookie(){
var name = document.getElementById("erase").value;
Cookie.eraseCookie(name);
document.getElementById("paragraph").innerText = "Cookie Erased: " + name;
}
</script>
</body>


</html>

and that’s pretty much it for this article. Maybe you can get some use out of this. I hope you enjoyed this article.

QuickSort sorting algorithm in java with Generics that implement Comparable

In this article I’m going to touch on the sorting algorithm called Quicksort. Its worst case time complexity is O(n^2) and its best case time complexity is O(nlogn). Firstly the method we are going to make is going to take a generic array and those elements should implement the Comparable interface so they can be sorted. Take this Circle class for example. When you implement the Comparable interface you specify in the compareTomethod what makes a circle greater than, less than, or equal to another circle. In this example we return whether the radius of the circle is bigger or smaller than the circle it is being compared to.

Circle.java

/**
 * author: copypasteearth
 * date: 7/17/2019
 */
public class Circle implements Comparable<Circle> {
    public int xValue;
    public int yValue;
    public int radius;

@Override
public int compareTo(Circle o) {
return (this.radius - o.radius);
}
@Override
public String toString() {
return "x: " + xValue + " ---y: " + yValue + " ---radius: " + radius;
}
}

Next we create the Quicksort class that has the method quicksort and a main method to test out the quicksort method. The quicksort method is a recursive method and the base case is if(a < b). The method goes through the generic array and sorts the elements based on what the compareTo method tells it. Here is the Quicksort class.

Quicksort.java

/**
 * author: copypasteearth
 * date: 7/17/2019
 */
import java.util.Random;
public class QuickSort<T extends Comparable<T>> {

public static <T extends Comparable<T>> void quicksort(T[] array, int a, int b) {
if (a < b) {
int i = a, j = b;
T x = array[(i + j) / 2];

do {
while (array[i].compareTo(x) < 0) i++;
while (x.compareTo(array[j]) < 0) j--;

if ( i <= j) {
T tmp = array[i];
array[i] = array[j];
array[j] = tmp;
i++;
j--;
}

} while (i <= j);

quicksort(array, a, j);
quicksort(array, i, b);
}
}

public static void main(String[] args) {
Integer[] integerarray = {50, 55, 11, 89, 90, 1, 20, 11};
QuickSort<Integer> qsinteger = new QuickSort<Integer>();
qsinteger.quicksort(integerarray, 0, integerarray.length-1);
for(Integer i: integerarray) {
System.out.println(i);
}
String[] stringarray = {"bird","moth","apple","zebra","banana","desert","pig"};
QuickSort<String> qsstring = new QuickSort<String>();
qsstring.quicksort(stringarray, 0, stringarray.length-1);
for(String i: stringarray) {
System.out.println(i);
}
Circle[] circlearray = new Circle[20];
Random rand = new Random();
for (int index = 0; index < 20; index++)
{
circlearray[index] = new Circle();
circlearray[index].xValue = Math.abs(rand.nextInt()) % 100;
circlearray[index].yValue = Math.abs(rand.nextInt()) % 100;
circlearray[index].radius = Math.abs(rand.nextInt()) % 100;

}
System.out.println("Circle Array Unsorted....");
for(int i = 0;i < 20;i++){

System.out.println(circlearray[i]);
}
QuickSort<Circle> qscircle = new QuickSort<Circle>();
qscircle.quicksort(circlearray, 0, circlearray.length-1);
System.out.println("Circle Array Sorted");
for(Circle i: circlearray) {
System.out.println(i);
}

}

}

If you run this code you will see the results from the main method. First it sorts an Integer array and then a String array. Then it makes a Circle array and prints them out unsorted then it sorts them and then prints them out again sorted. That pretty much does it for this example on quicksorting. In the future I will probably go through the rest of the sorting algorithms. Hope you enjoyed it.

Donate or Subscribe to support Copypasteearth!!!!!

×
Your Donation
copypasteearth@gmail.com">

Obesity in the World Today

Obesity is a growing problem in today’s world.  You might ask what are the reasons that today’s people are more likely to be obese. People try to cut carbohydrates, sugar, fat, anything to live a healthier life these days and they feel even more pressured to do so because of the increasing epidemic of obesity.  There are a lot of factors that can contribute to a person being obese which are diet and exercise.  Through the right diet and exercise a person will not even have to worry about obesity.

Being on a diet is important because everyone is on one.  If you weren’t on a diet you would be dead from starvation.  Everyone is different having to do with genetics and how they are affected by the environment. Culture is another factor that has a lot to do with diet.  Some people cannot eat sugar and are diabetics and sugar intake has increased at an order of magnitude or even higher since the 80’s when I was a kid.  Everything has sugar in it these days and is probably the main culprit in the obesity craze.  Regulating sugar intake is probably important so you don’t eventually become diabetic.  Some people say that cutting carbohydrates is a good way to battle obesity.  Why are companies packing their foods with sugar?  Because sugar tastes good and it is an inborn preference to love the sweet mother’s milk when a child is just born.  Whether companies took advantage of this innate preference is besides the point that people really need to watch their diets so that they do not run into health problems like obesity.  Some people can eat all of the junk food they want and not gain a pound.  I know this because I am one of those people.  But since I’ve been getting older I have started to watch my diet because cholesterol is really building up inside me.  So everyone is on a diet and the point is that you have to be aware of your diet and change it so you can stay healthy.

Exercise these days seems to be a thing of the past.  When I was young back in the 1980’s I was outside at the parks every day running around, wading through the creek, and building tree forts.  These days the kids want to not even move and look at their tablets and smart devices.  You probably don’t burn a lot of calories when you don’t even move.  Exercise is important for everyday functioning.  I recently read an article that said your memory improves when you exercise because it enlarges your hippocampus, the area of your brain that is used for memory.  So exercise enlarges your brain and burns calories.  Calories left over at the end of the day turn to fat when you sleep.  I cannot urge it enough these days that the kids need to exercise in order to stay healthy.  I always take my nieces to the park so they can run around and play with other kids and get out some of the energy that they have from calories in the food they eat.  I used to run 5 miles at once, once a week and I am going to try to start it up again to lower my cholesterol.  Exercising will lead to having a faster metabolism.  The faster your metabolism the quicker you will burn calories and fat.  If you have a fast metabolism you would never even have to worry about obesity, ever.

To conclude I’d like to again stress the effects of diet and exercise on the disease of obesity that has struck our country in the past couple decades.  As far as diet is concerned watch how much sugar, carbohydrates, fats, and calories you take in.  And for exercise, make sure you go out regularly and stay active so you can burn all those calories and speed up your metabolism.  Being healthy requires a proper diet and exercise regimen to stay clear of obesity.

How to make a mouse maze in Java

This is the code to make a mouse maze with recursion using a stack and a list with a GUI in Java.

First we will make a Mouse class

Mouse.java

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Mouse {
public int x,y;
public Stack<Coordinate> decisions;
public List<Coordinate> solution;

public Mouse(int x, int y){
this.x = x;
this.y = y;
decisions = new Stack<Coordinate>();
solution = new ArrayList<Coordinate>();
}
}

Then we will make the coordinate class

Coordinate.java

public class Coordinate {
public int x,y;

public Coordinate(int x,int y){
this.x = x;
this.y = y;
}

@Override
public boolean equals(Object obj) {

boolean sameSame = false;
if (obj != null && obj instanceof Coordinate)
{
if(this.x == ((Coordinate)obj).x && this.y == ((Coordinate)obj).y){
sameSame = true;
}

}
return sameSame;
}
}

Now its time for the decision class

Decision.java

public class Decision {

public boolean up,down,left,right;
public int x,y;
public Decision(int x, int y){
up = down = left = right = false;
this.x = x;
this.y = y;
}
public Decision(boolean up,boolean down,boolean right,boolean left){
this.up = up;
this.down = down;
this.right = right;
this.left = left;
}
public void setLeft(boolean left){
this.left = left;
}
public void setRight(boolean right){
this.right = right;
}
public void setUp(boolean up){
this.up = up;
}
public void setDown(boolean down){
this.down = down;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return x + " x -- y " + y;
}

}

Now we have to make the maze class which does most of the hard work

Maze.java

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JComponent;

public class Maze extends JComponent{
public char[][] maze = null;
public Rectangle[][] rects = null;
public boolean mousebool = false;
public boolean backtrack = false;
public Mouse mouse;
public Random random = new Random();
public Coordinate startingPoint;
public boolean first = true;
public boolean solv = true;
public int lastx,lasty;
public String navigation = "working!!!";

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);

if(maze != null){
for(int i = 0;i < maze.length;i++){
for(int j = 0;j < maze[0].length;j++){
if(maze[i][j] == '1'){
g.setColor(Color.BLACK);
g.fillRect(rects[i][j].x, rects[i][j].y, rects[i][j].width, rects[i][j].height);
g.setColor(Color.WHITE);
g.drawRect(rects[i][j].x, rects[i][j].y, rects[i][j].width, rects[i][j].height);
}else if(maze[i][j] == '0'){
g.setColor(Color.white);
g.fillRect(rects[i][j].x, rects[i][j].y, rects[i][j].width, rects[i][j].height);
g.setColor(Color.BLACK);
g.drawRect(rects[i][j].x, rects[i][j].y, rects[i][j].width, rects[i][j].height);
}
}
}
if(mousebool){
g.setColor(Color.PINK);

g.fillOval(rects[mouse.x][mouse.y].x, rects[mouse.x][mouse.y].y, rects[mouse.x][mouse.y].width, rects[mouse.x][mouse.y].height);
}
}

}
public void setMaze(char[][] maze){
mousebool = false;
this.maze = maze;
rects = new Rectangle[maze.length][maze[0].length];
for(int i = 0;i < rects.length;i++){
for(int j = 0;j < rects[0].length;j++){
rects[i][j] = new Rectangle(i * (getWidth()/rects.length),j * (getHeight()/rects[0].length)
,getWidth()/rects.length,getHeight()/rects[0].length);
}
}
repaint();
}
public void setMouse(int x,int y){
mousebool = true;
mouse = new Mouse(x,y);
startingPoint = new Coordinate(x,y);
mouse.solution.add(new Coordinate(x,y));
mouse.decisions.push(new Coordinate(x,y));
first = true;

repaint();
}
public void solve(){

if(mouse.x > 0 && mouse.x < maze.length - 1 && mouse.y > 0 && mouse.y < maze[0].length - 1 && mouse.decisions.size() > 0){

//System.out.println(wasHere(coord) + "now");
//north
System.out.println(wasHere(new Coordinate(mouse.x,mouse.y - 1)) + "north");
if (!(maze[mouse.x][mouse.y - 1] == '1') && !wasHere(new Coordinate(mouse.x,mouse.y - 1))) mouse.decisions.push(new Coordinate(mouse.x,mouse.y - 1));
//east
System.out.println(wasHere(new Coordinate(mouse.x + 1,mouse.y)) + "east");
if (!(maze[mouse.x + 1][mouse.y] == '1') && !wasHere(new Coordinate(mouse.x + 1,mouse.y))) mouse.decisions.push(new Coordinate(mouse.x + 1,mouse.y));
//west
if (!(maze[mouse.x - 1][mouse.y] == '1') && !wasHere(new Coordinate(mouse.x - 1,mouse.y))) mouse.decisions.push(new Coordinate(mouse.x - 1,mouse.y));
//south
if(!(maze[mouse.x][mouse.y + 1] == '1') && !wasHere(new Coordinate(mouse.x,mouse.y + 1))) mouse.decisions.push(new Coordinate(mouse.x,mouse.y + 1));

Coordinate coord = mouse.decisions.pop();

mouse.x = coord.x;
mouse.y = coord.y;

mouse.solution.add(coord);

ActionListener taskPerformer = new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
solve();

}
};
javax.swing.Timer t = new javax.swing.Timer( 250, taskPerformer);
t.setRepeats(false);
t.start();
//solve();

repaint();
}else{
solv = false;
if(mouse.decisions.size() == 0){
mouse.solution.clear();
navigation = "there is no solution";
}else{
mouse.solution.clear();
findPath(startingPoint.x,startingPoint.y);
navigation = "maze complete";
}
}

//solve();
}
public boolean findPath(int x,int y){
if(x < 0 || y < 0 || x > maze.length - 1 || y > maze[0].length - 1)return false;

if(!(x > 0 && x < maze.length - 1 && y > 0 && y < maze[0].length - 1) && maze[x][y] == '0')
{
mouse.solution.add(new Coordinate(x,y));
return true;// && maze[x][y] == '0') return true;//&& maze[x][y] == '0') return true;
}
if(maze[x][y] == '1') return false;

mouse.solution.add(new Coordinate(x,y));
if(!mouse.solution.contains(new Coordinate(x,y - 1)))
if(findPath(x,y-1) == true) return true;
if(!mouse.solution.contains(new Coordinate(x+1,y)))
if(findPath(x + 1,y) == true) return true;
if(!mouse.solution.contains(new Coordinate(x,y+1)))
if(findPath(x,y + 1)== true) return true;
if(!mouse.solution.contains(new Coordinate(x-1,y)))
if(findPath(x - 1,y)== true) return true;
mouse.solution.remove(new Coordinate(x,y));
return false;
}

public boolean wasHere(Coordinate coord){
return mouse.solution.contains(coord);
}
public void TraverseMouse(int x){
if(x < mouse.solution.size()){
Coordinate coord = mouse.solution.get(x);
mouse.x = coord.x;
mouse.y = coord.y;
final int xt = x+=1;
ActionListener taskPerformer = new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
TraverseMouse(xt);

}
};
javax.swing.Timer t = new javax.swing.Timer( 250, taskPerformer);
t.setRepeats(false);
t.start();
}
repaint();

}
public String Navigation(){
return navigation;
}
}

And finally the Main class to make the GUI

Main.java

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;

public class Main {
public static int width;
public static int height;
public static char[][] maze1;
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception ex) {
ex.printStackTrace();
}

SwingUtilities.invokeLater(new Runnable() {
public void run() {
create();
}
});

}
public static void create(){
JFrame frame = new JFrame("Mouse Maze");
final Maze maze = new Maze();
frame.setSize(500, 500);
frame.setLocation((int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2)-264,
(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2)-330);
maze.setSize(400, 400);
Container content = frame.getContentPane();
//Creates a new container
content.setLayout(new BorderLayout());

frame.add(maze,BorderLayout.CENTER);
//frame.add(maze);
JPanel panel = new JPanel(new BorderLayout());
JPanel panel1 = new JPanel(new BorderLayout());
JPanel panel2 = new JPanel(new BorderLayout());
JPanel finish = new JPanel(new BorderLayout());
final JLabel textFile = new JLabel(" ex: maze.txt ");
JButton pickFile = new JButton("Pick file");
pickFile.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
".txt file", "txt");
chooser.setFileFilter(filter);

int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) {
try {
BufferedReader read = new BufferedReader(new FileReader(chooser.getSelectedFile()));
String rea = read.readLine();
String[] split = rea.split(" ");
width = Integer.valueOf(split[0]);
height = Integer.valueOf(split[1]);

String readline;
int num = 0;
maze1 = new char[width][height];
while((readline = read.readLine()) != null){
char[] ch = readline.toCharArray();
for(int i = 0;i < ch.length;i++){
maze1[i][num] = ch[i];
}
num++;
}
maze.setMaze(maze1);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
textFile.setText(chooser.getSelectedFile().getName());
}else{

}
}

});

panel.add(pickFile,BorderLayout.CENTER);
panel.add(textFile,BorderLayout.WEST);
JButton setMouse = new JButton("Set Mouse");
final JTextField mouseText = new JTextField("x,y",15);
JButton solve = new JButton("SOLVE");
JButton traverse = new JButton("TRAVERSE");
final JLabel error = new JLabel("ERROR MESSAGES!!!!");
panel2.add(solve,BorderLayout.NORTH);
panel2.add(traverse,BorderLayout.CENTER);
panel2.add(error,BorderLayout.SOUTH);
panel1.add(setMouse,BorderLayout.CENTER);
panel1.add(mouseText,BorderLayout.WEST);
finish.add(panel,BorderLayout.NORTH);
finish.add(panel1,BorderLayout.CENTER);
finish.add(panel2,BorderLayout.SOUTH);
//content.setLayout(new BorderLayout());
content.add(finish, BorderLayout.SOUTH);
traverse.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
maze.TraverseMouse(0);
}

});
solve.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub

maze.solve();

error.setText(maze.navigation);

}

});
setMouse.addActionListener(new ActionListener(){

@Override
public void actionPerformed(ActionEvent arg0) {
String mousePosition = mouseText.getText();
String[] splitposition = mousePosition.split(",");
try{
int x = Integer.valueOf(splitposition[0]);
int y = Integer.valueOf(splitposition[1]);
if(x >= width || y >= height){
error.setText("those coordinates are not in range of your maze, try again, 0-"+ (width - 1)+",0-"+(height-1));
}else if(maze1[x][y] == '1'){
error.setText("you cannot place the mouse on a wall, try again");
}else{
maze.setMouse(x, y);
error.setText("coordinates set.");
}
}catch(NumberFormatException e){
error.setText("You Must enter the mouse position \"x,y\" example: 10,20");
}catch(ArrayIndexOutOfBoundsException e){
e.printStackTrace();
error.setText("You Must enter the mouse position \"x,y\" example: 10,20");
}

}

});

//frame.add(panel);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//makes it so you can close
frame.setVisible(true);
//char[][] ch = new char[][]{{'1','1','1','1'},{'1','0','0','1'},{'1','0','0','1'},{'1','1','1','1'}};
//maze.setMaze(ch);
}

}

You will have to use a text file in this format where a 1 is a wall and a 0 is part of the path remember .txt file the first line means 10 width and 5 height for the maze


10 5
1111111111
1010001111
1011011111
1011000011
1111111111

You can try it and alter it to your own code, thanks for reading.

Donate or Subscribe to support Copypasteearth!!!!!


×
Your Donation

Genie Lamp Free a silly app for android!!!

Genie Lamp Free is a funny voice recognition app where you rub the lamp and make a wish to a genie and the genie gives a reply based on what you say.  The app has over 5,000 downloads on google play store. Genie Lamp Free is where you can go to try the game. Its awesome because its free and you might get a few kicks out of it.

So go download GenieLampFree and leave a review for the developer jacs@pps on google play store.  As far as I know its the only genie in a lamp app that you can actually talk to.  They have a lot of great apps on there who knows what those guys are up to. The app is just for entertainment purposes and only available for android devices so I guess that’s too bad for all the apple gurus out there. Thanks for reading and go download that app. 😉

%d bloggers like this: