| | |
Read class from another class
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 56
Reputation:
Solved Threads: 4
helo, can any one help to read one class from another class. i em knew with java actually. i got class a which has got sub class b static class. now i em trying to access class a from another class c using button. when in class c user click on button class a should load. is there any one there to help.... thank you in advance
Emint
Emint
Last edited by emint; Jul 2nd, 2009 at 6:13 pm.
emint,
Don't say "thank you in advance", we have to talk more yet.
I think you want to create an object of class A.
A.java
C.java
Don't say "thank you in advance", we have to talk more yet.
I think you want to create an object of class A.
A.java
Java Syntax (Toggle Plain Text)
public class A { public A() // Constructor { System.out.println("A"); } // class B is Sub class of A and it is static public static class B extends A { public B() //Constructor { System.out.println("B"); } } }
C.java
Java Syntax (Toggle Plain Text)
public class C { public static void main(String []args){ A a=new A(); // Create an object of class A A.B b=new A.B(); // Create an object of class B } }
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Jun 2009
Posts: 56
Reputation:
Solved Threads: 4
Thank you for your reply. yes i did what you said. it works but i got program as i told you earlier class A has got sub class B as static when i run them they works fine. but wen i try to from class c it give an error. i dun know where i m makin mistake. i m attachin my code here. you can have look.
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class Maze extends JFrame
{
public static String a, b, c;
public static final int TILE_SIZE = 20;
public Maze()
{
// super("Maze algorithm program");
RunDB runDB = new RunDB();
try{
runDB.loadDriver();
runDB.makeConnection();
runDB.buildStatement();
runDB.executeQuery();
String x;
x = runDB.text;
c = x.substring(6, 9);
b = x.substring(3, 6);
a = x.substring(0, 3);
}catch(Exception e){
e.printStackTrace();
}
}
String maze = a+b+c;
int width = (int)Math.sqrt(maze.length());
Screen screen;
void searchExit(Screen screen, int milliseconds) {
this.screen = screen;
int[] startCoordinates = getCoordinates(maze.indexOf("S"));
maze = visit(maze, startCoordinates[0], startCoordinates[1]);
}
String visit(String maze, int x, int y) {
screen.showMaze(maze,0);
if (foundExit(maze))
return maze;
if (isEmpty(maze, x - 1, y)) {
String newMaze = moveLeft(maze, x, y);
String visitedNewMaze = visit(newMaze, x - 1, y);
if (foundExit(visitedNewMaze))
return visitedNewMaze;
}
if (isEmpty(maze, x, y - 1)) {
String newMaze = moveUp(maze, x, y);
String visitedNewMaze = visit(newMaze, x, y - 1);
if (foundExit(visitedNewMaze))
return visitedNewMaze;
}
if (isEmpty(maze, x + 1, y)) {
String newMaze = moveRight(maze, x, y);
String visitedNewMaze = visit(newMaze, x + 1, y);
if (foundExit(visitedNewMaze))
return visitedNewMaze;
}
if (isEmpty(maze, x, y + 1)) {
String newMaze = moveDown(maze, x, y);
String visitedNewMaze = visit(newMaze, x, y + 1);
if (foundExit(visitedNewMaze))
return visitedNewMaze;
}
return maze;
}
int[] getCoordinates(int pos) {
return new int[] { pos % width, pos / width };
}
int getPosition(int x, int y) {
return y * width + x;
}
boolean isInsideMaze(String maze, int x, int y) {
if (x < 0 || x >= width)
return false;
if (y < 0 || y >= width)
return false;
int pos = getPosition(x, y);
return pos >= 0 && pos < maze.length();
}
char look(String maze, int x, int y) {
return maze.charAt(getPosition(x, y));
}
boolean isEmpty(String maze, int x, int y) {
if (!isInsideMaze(maze, x, y))
return false;
return look(maze, x, y) == 'P';
}
static int cnt = 0;
boolean isExit(String maze, int x, int y) {
if (!isInsideMaze(maze, x, y))
return false;
return look(maze, x, y) == 'E';
}
boolean isStone(String maze, int x, int y) {
if (!isInsideMaze(maze, x, y))
return false;
return look(maze, x, y) == '.';
}
boolean foundExit(String maze) {
cnt++;
if (cnt % 100 == 0)
System.out.println(cnt);
int[] exitCoordinates = getCoordinates(maze.indexOf('E'));
if (isStone(maze, exitCoordinates[0] - 1, exitCoordinates[1])) {
return true;
}
if (isStone(maze, exitCoordinates[0], exitCoordinates[1] - 1)) {
return true;
}
if (isStone(maze, exitCoordinates[0] + 1, exitCoordinates[1])) {
return true;
}
if (isStone(maze, exitCoordinates[0], exitCoordinates[1] + 1)) {
return true;
}
return false;
}
String setStone(String maze, int x, int y) {
int pos = getPosition(x, y);
return maze.substring(0, pos) + '.'
+ maze.substring(pos + 1, maze.length());
}
String moveUp(String maze, int x, int y) {
return setStone(maze, x, y - 1);
}
String moveDown(String maze, int x, int y) {
return setStone(maze, x, y + 1);
}
String moveLeft(String maze, int x, int y) {
return setStone(maze, x - 1, y);
}
String moveRight(String maze, int x, int y) {
return setStone(maze, x + 1, y);
}
static class Screen extends Maze {
int WIDTH = 500;
String maze = "";
public Screen() {
setSize(500,700 );
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void addComponent(String region, Component component) {
Panel panel = new Panel();
panel.add(component);
add(region, panel); // make sure you add the panel!
}
public void paint(Graphics g) {
BufferedImage image = (BufferedImage) createImage(WIDTH, WIDTH);
Graphics g2 = image.getGraphics();
g2.setColor(Color.GRAY);
g2.fillRect(0, 0, WIDTH, WIDTH);
int n = (int) Math.sqrt(maze.length());
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
char type = maze.charAt(i + j * n);
drawMazeArea(g2, i, j, n, type);
g2.fillRect(i*TILE_SIZE,j*TILE_SIZE,TILE_SIZE,TILE_SIZE);
g.setColor(g.getColor().darker());
g2.drawRect(i*TILE_SIZE,j*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
}
g.drawImage(image, 0, 0, this);
}
void drawMazeArea(Graphics g, int i, int j, int n, char type) {
if (type == 'O')
{
g.setColor(Color.BLUE);
}
if (type == 'P')
{
g.setColor(Color.WHITE);
g.fillRect('P'*TILE_SIZE,'P'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
//g.setColor(g.getColor().darker());
g.drawRect('P'*TILE_SIZE,'P'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
if (type == 'S')
{
g.setColor(Color.RED);
g.fillRect('S'*TILE_SIZE,'S'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
//g.setColor(g.getColor().darker());
g.drawRect('S'*TILE_SIZE,'S'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
if( type == '.')
{
g.setColor(Color.YELLOW);
g.fillRect('.'*TILE_SIZE,'.'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
//g.setColor(g.getColor().darker());
g.drawRect('.'*TILE_SIZE,'.'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
if (type == 'E')
{
g.setColor(Color.GREEN);
g.fillRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
//g.setColor(g.getColor().darker());
g.drawRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
int r = WIDTH / (n + 3);
int x = i * r + r, y = j * r + r, width = r, height = r;
g.fillRect(x, y, width, height);
g.setColor(Color.WHITE);
if (type == 'S')
g.fillArc(x + r / 4, y + r / 4, width / 2, height / 2, 0, 360);
if (type == 'E'){
g.fillArc(x + r / 4, y + r / 4, width / 2, height / 2, 0, 360);
g.setColor(Color.black); }
g.fillRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
g.setColor(g.getColor().darker());
g.drawRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
void showMaze(String maze, int milliseconds) {
int a = milliseconds;
a = 1500;
this.maze = maze;
repaint();
try {
Thread.sleep(a);
} catch (Exception e) {
}
}
public void update(Graphics g) {
paint(g);
}
}
public static void main(String [] a)
{ Screen screen = new Screen();
Maze maze = new Maze();
Button sm = new Button(" Solve Maze ");
Button exit = new Button(" Exit ");
TextField tb = new TextField(20 );
Label button = new Label(" Algorithm: ");
sm.setBackground(Color.green);
exit.setBackground(Color.red);
button.setBackground(Color.pink);
screen.add(button);
screen.add(tb );
screen.add(sm );
screen.add(exit );
screen.setLayout(new FlowLayout());
screen.setVisible(true);
int milliseconds = 4000;
maze.searchExit(screen, milliseconds);
}
}
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import javax.swing.*;
public class Maze extends JFrame
{
public static String a, b, c;
public static final int TILE_SIZE = 20;
public Maze()
{
// super("Maze algorithm program");
RunDB runDB = new RunDB();
try{
runDB.loadDriver();
runDB.makeConnection();
runDB.buildStatement();
runDB.executeQuery();
String x;
x = runDB.text;
c = x.substring(6, 9);
b = x.substring(3, 6);
a = x.substring(0, 3);
}catch(Exception e){
e.printStackTrace();
}
}
String maze = a+b+c;
int width = (int)Math.sqrt(maze.length());
Screen screen;
void searchExit(Screen screen, int milliseconds) {
this.screen = screen;
int[] startCoordinates = getCoordinates(maze.indexOf("S"));
maze = visit(maze, startCoordinates[0], startCoordinates[1]);
}
String visit(String maze, int x, int y) {
screen.showMaze(maze,0);
if (foundExit(maze))
return maze;
if (isEmpty(maze, x - 1, y)) {
String newMaze = moveLeft(maze, x, y);
String visitedNewMaze = visit(newMaze, x - 1, y);
if (foundExit(visitedNewMaze))
return visitedNewMaze;
}
if (isEmpty(maze, x, y - 1)) {
String newMaze = moveUp(maze, x, y);
String visitedNewMaze = visit(newMaze, x, y - 1);
if (foundExit(visitedNewMaze))
return visitedNewMaze;
}
if (isEmpty(maze, x + 1, y)) {
String newMaze = moveRight(maze, x, y);
String visitedNewMaze = visit(newMaze, x + 1, y);
if (foundExit(visitedNewMaze))
return visitedNewMaze;
}
if (isEmpty(maze, x, y + 1)) {
String newMaze = moveDown(maze, x, y);
String visitedNewMaze = visit(newMaze, x, y + 1);
if (foundExit(visitedNewMaze))
return visitedNewMaze;
}
return maze;
}
int[] getCoordinates(int pos) {
return new int[] { pos % width, pos / width };
}
int getPosition(int x, int y) {
return y * width + x;
}
boolean isInsideMaze(String maze, int x, int y) {
if (x < 0 || x >= width)
return false;
if (y < 0 || y >= width)
return false;
int pos = getPosition(x, y);
return pos >= 0 && pos < maze.length();
}
char look(String maze, int x, int y) {
return maze.charAt(getPosition(x, y));
}
boolean isEmpty(String maze, int x, int y) {
if (!isInsideMaze(maze, x, y))
return false;
return look(maze, x, y) == 'P';
}
static int cnt = 0;
boolean isExit(String maze, int x, int y) {
if (!isInsideMaze(maze, x, y))
return false;
return look(maze, x, y) == 'E';
}
boolean isStone(String maze, int x, int y) {
if (!isInsideMaze(maze, x, y))
return false;
return look(maze, x, y) == '.';
}
boolean foundExit(String maze) {
cnt++;
if (cnt % 100 == 0)
System.out.println(cnt);
int[] exitCoordinates = getCoordinates(maze.indexOf('E'));
if (isStone(maze, exitCoordinates[0] - 1, exitCoordinates[1])) {
return true;
}
if (isStone(maze, exitCoordinates[0], exitCoordinates[1] - 1)) {
return true;
}
if (isStone(maze, exitCoordinates[0] + 1, exitCoordinates[1])) {
return true;
}
if (isStone(maze, exitCoordinates[0], exitCoordinates[1] + 1)) {
return true;
}
return false;
}
String setStone(String maze, int x, int y) {
int pos = getPosition(x, y);
return maze.substring(0, pos) + '.'
+ maze.substring(pos + 1, maze.length());
}
String moveUp(String maze, int x, int y) {
return setStone(maze, x, y - 1);
}
String moveDown(String maze, int x, int y) {
return setStone(maze, x, y + 1);
}
String moveLeft(String maze, int x, int y) {
return setStone(maze, x - 1, y);
}
String moveRight(String maze, int x, int y) {
return setStone(maze, x + 1, y);
}
static class Screen extends Maze {
int WIDTH = 500;
String maze = "";
public Screen() {
setSize(500,700 );
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void addComponent(String region, Component component) {
Panel panel = new Panel();
panel.add(component);
add(region, panel); // make sure you add the panel!
}
public void paint(Graphics g) {
BufferedImage image = (BufferedImage) createImage(WIDTH, WIDTH);
Graphics g2 = image.getGraphics();
g2.setColor(Color.GRAY);
g2.fillRect(0, 0, WIDTH, WIDTH);
int n = (int) Math.sqrt(maze.length());
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
char type = maze.charAt(i + j * n);
drawMazeArea(g2, i, j, n, type);
g2.fillRect(i*TILE_SIZE,j*TILE_SIZE,TILE_SIZE,TILE_SIZE);
g.setColor(g.getColor().darker());
g2.drawRect(i*TILE_SIZE,j*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
}
g.drawImage(image, 0, 0, this);
}
void drawMazeArea(Graphics g, int i, int j, int n, char type) {
if (type == 'O')
{
g.setColor(Color.BLUE);
}
if (type == 'P')
{
g.setColor(Color.WHITE);
g.fillRect('P'*TILE_SIZE,'P'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
//g.setColor(g.getColor().darker());
g.drawRect('P'*TILE_SIZE,'P'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
if (type == 'S')
{
g.setColor(Color.RED);
g.fillRect('S'*TILE_SIZE,'S'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
//g.setColor(g.getColor().darker());
g.drawRect('S'*TILE_SIZE,'S'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
if( type == '.')
{
g.setColor(Color.YELLOW);
g.fillRect('.'*TILE_SIZE,'.'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
//g.setColor(g.getColor().darker());
g.drawRect('.'*TILE_SIZE,'.'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
if (type == 'E')
{
g.setColor(Color.GREEN);
g.fillRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
//g.setColor(g.getColor().darker());
g.drawRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
int r = WIDTH / (n + 3);
int x = i * r + r, y = j * r + r, width = r, height = r;
g.fillRect(x, y, width, height);
g.setColor(Color.WHITE);
if (type == 'S')
g.fillArc(x + r / 4, y + r / 4, width / 2, height / 2, 0, 360);
if (type == 'E'){
g.fillArc(x + r / 4, y + r / 4, width / 2, height / 2, 0, 360);
g.setColor(Color.black); }
g.fillRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
g.setColor(g.getColor().darker());
g.drawRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE);
}
void showMaze(String maze, int milliseconds) {
int a = milliseconds;
a = 1500;
this.maze = maze;
repaint();
try {
Thread.sleep(a);
} catch (Exception e) {
}
}
public void update(Graphics g) {
paint(g);
}
}
public static void main(String [] a)
{ Screen screen = new Screen();
Maze maze = new Maze();
Button sm = new Button(" Solve Maze ");
Button exit = new Button(" Exit ");
TextField tb = new TextField(20 );
Label button = new Label(" Algorithm: ");
sm.setBackground(Color.green);
exit.setBackground(Color.red);
button.setBackground(Color.pink);
screen.add(button);
screen.add(tb );
screen.add(sm );
screen.add(exit );
screen.setLayout(new FlowLayout());
screen.setVisible(true);
int milliseconds = 4000;
maze.searchExit(screen, milliseconds);
}
}
emint,
Use BB code tags. Source code must be surrounded with bb code tags. See # icon at toolbar. Read How to use bb code tag?
Use BB code tags. Source code must be surrounded with bb code tags. See # icon at toolbar. Read How to use bb code tag?
Last edited by adatapost; Jul 3rd, 2009 at 7:55 am.
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Jun 2009
Posts: 56
Reputation:
Solved Threads: 4
Java Syntax (Toggle Plain Text)
import java.io.*; import java.awt.*; import java.awt.event.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import javax.swing.*; public class Maze extends JFrame { public static String a, b, c; public static final int TILE_SIZE = 20; public Maze() { // super("Maze algorithm program"); RunDB runDB = new RunDB(); try{ runDB.loadDriver(); runDB.makeConnection(); runDB.buildStatement(); runDB.executeQuery(); String x; x = runDB.text; c = x.substring(6, 9); b = x.substring(3, 6); a = x.substring(0, 3); }catch(Exception e){ e.printStackTrace(); } } String maze = a+b+c; int width = (int)Math.sqrt(maze.length()); Screen screen; void searchExit(Screen screen, int milliseconds) { this.screen = screen; int[] startCoordinates = getCoordinates(maze.indexOf("S")); maze = visit(maze, startCoordinates[0], startCoordinates[1]); } String visit(String maze, int x, int y) { screen.showMaze(maze,0); if (foundExit(maze)) return maze; if (isEmpty(maze, x - 1, y)) { String newMaze = moveLeft(maze, x, y); String visitedNewMaze = visit(newMaze, x - 1, y); if (foundExit(visitedNewMaze)) return visitedNewMaze; } if (isEmpty(maze, x, y - 1)) { String newMaze = moveUp(maze, x, y); String visitedNewMaze = visit(newMaze, x, y - 1); if (foundExit(visitedNewMaze)) return visitedNewMaze; } if (isEmpty(maze, x + 1, y)) { String newMaze = moveRight(maze, x, y); String visitedNewMaze = visit(newMaze, x + 1, y); if (foundExit(visitedNewMaze)) return visitedNewMaze; } if (isEmpty(maze, x, y + 1)) { String newMaze = moveDown(maze, x, y); String visitedNewMaze = visit(newMaze, x, y + 1); if (foundExit(visitedNewMaze)) return visitedNewMaze; } return maze; } int[] getCoordinates(int pos) { return new int[] { pos % width, pos / width }; } int getPosition(int x, int y) { return y * width + x; } boolean isInsideMaze(String maze, int x, int y) { if (x < 0 || x >= width) return false; if (y < 0 || y >= width) return false; int pos = getPosition(x, y); return pos >= 0 && pos < maze.length(); } char look(String maze, int x, int y) { return maze.charAt(getPosition(x, y)); } boolean isEmpty(String maze, int x, int y) { if (!isInsideMaze(maze, x, y)) return false; return look(maze, x, y) == 'P'; } static int cnt = 0; boolean isExit(String maze, int x, int y) { if (!isInsideMaze(maze, x, y)) return false; return look(maze, x, y) == 'E'; } boolean isStone(String maze, int x, int y) { if (!isInsideMaze(maze, x, y)) return false; return look(maze, x, y) == '.'; } boolean foundExit(String maze) { cnt++; if (cnt % 100 == 0) System.out.println(cnt); int[] exitCoordinates = getCoordinates(maze.indexOf('E')); if (isStone(maze, exitCoordinates[0] - 1, exitCoordinates[1])) { return true; } if (isStone(maze, exitCoordinates[0], exitCoordinates[1] - 1)) { return true; } if (isStone(maze, exitCoordinates[0] + 1, exitCoordinates[1])) { return true; } if (isStone(maze, exitCoordinates[0], exitCoordinates[1] + 1)) { return true; } return false; } String setStone(String maze, int x, int y) { int pos = getPosition(x, y); return maze.substring(0, pos) + '.' + maze.substring(pos + 1, maze.length()); } String moveUp(String maze, int x, int y) { return setStone(maze, x, y - 1); } String moveDown(String maze, int x, int y) { return setStone(maze, x, y + 1); } String moveLeft(String maze, int x, int y) { return setStone(maze, x - 1, y); } String moveRight(String maze, int x, int y) { return setStone(maze, x + 1, y); } static class Screen extends Maze { int WIDTH = 500; String maze = ""; public Screen() { setSize(500,700 ); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public void addComponent(String region, Component component) { Panel panel = new Panel(); panel.add(component); add(region, panel); // make sure you add the panel! } public void paint(Graphics g) { BufferedImage image = (BufferedImage) createImage(WIDTH, WIDTH); Graphics g2 = image.getGraphics(); g2.setColor(Color.GRAY); g2.fillRect(0, 0, WIDTH, WIDTH); int n = (int) Math.sqrt(maze.length()); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { char type = maze.charAt(i + j * n); drawMazeArea(g2, i, j, n, type); g2.fillRect(i*TILE_SIZE,j*TILE_SIZE,TILE_SIZE,TILE_SIZE); g.setColor(g.getColor().darker()); g2.drawRect(i*TILE_SIZE,j*TILE_SIZE,TILE_SIZE,TILE_SIZE); } } g.drawImage(image, 0, 0, this); } void drawMazeArea(Graphics g, int i, int j, int n, char type) { if (type == 'O') { g.setColor(Color.BLUE); } if (type == 'P') { g.setColor(Color.WHITE); g.fillRect('P'*TILE_SIZE,'P'*TILE_SIZE,TILE_SIZE,TILE_SIZE); //g.setColor(g.getColor().darker()); g.drawRect('P'*TILE_SIZE,'P'*TILE_SIZE,TILE_SIZE,TILE_SIZE); } if (type == 'S') { g.setColor(Color.RED); g.fillRect('S'*TILE_SIZE,'S'*TILE_SIZE,TILE_SIZE,TILE_SIZE); //g.setColor(g.getColor().darker()); g.drawRect('S'*TILE_SIZE,'S'*TILE_SIZE,TILE_SIZE,TILE_SIZE); } if( type == '.') { g.setColor(Color.YELLOW); g.fillRect('.'*TILE_SIZE,'.'*TILE_SIZE,TILE_SIZE,TILE_SIZE); //g.setColor(g.getColor().darker()); g.drawRect('.'*TILE_SIZE,'.'*TILE_SIZE,TILE_SIZE,TILE_SIZE); } if (type == 'E') { g.setColor(Color.GREEN); g.fillRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE); //g.setColor(g.getColor().darker()); g.drawRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE); } int r = WIDTH / (n + 3); int x = i * r + r, y = j * r + r, width = r, height = r; g.fillRect(x, y, width, height); g.setColor(Color.WHITE); if (type == 'S') g.fillArc(x + r / 4, y + r / 4, width / 2, height / 2, 0, 360); if (type == 'E'){ g.fillArc(x + r / 4, y + r / 4, width / 2, height / 2, 0, 360); g.setColor(Color.black); } g.fillRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE); g.setColor(g.getColor().darker()); g.drawRect('E'*TILE_SIZE,'E'*TILE_SIZE,TILE_SIZE,TILE_SIZE); } void showMaze(String maze, int milliseconds) { int a = milliseconds; a = 1500; this.maze = maze; repaint(); try { Thread.sleep(a); } catch (Exception e) { } } public void update(Graphics g) { paint(g); } } public static void main(String [] a) { Screen screen = new Screen(); Maze maze = new Maze(); Button sm = new Button(" Solve Maze "); Button exit = new Button(" Exit "); TextField tb = new TextField(20 ); Label button = new Label(" Algorithm: "); sm.setBackground(Color.green); exit.setBackground(Color.red); button.setBackground(Color.pink); screen.add(button); screen.add(tb ); screen.add(sm ); screen.add(exit ); screen.setLayout(new FlowLayout()); screen.setVisible(true); int milliseconds = 4000; maze.searchExit(screen, milliseconds); } }
![]() |
Similar Threads
- read-only variables in a class (C++)
- problem with class and sub-class (C++)
- pass an interger from one class to others class (Java)
- Accessing a method from class 1 in class 3 (C++)
- Difference between a Template Class and a Class Template (C++)
- Java Class Class problem (Java)
- Class in a class... (Java)
- Python - Importing Data with a Class (Python)
- Reading an input file as a class memeber function (C++)
- HELP: class static function - compile errors (C++)
Other Threads in the Java Forum
- Previous Thread: exception in thread main java .lang.NoClassDefFoundError:Abc
- Next Thread: Fibonacci Problem
| Thread Tools | Search this Thread |
6 actuate android api applet application applications array arrays automation balls bank binary bluetooth bold business c++ chat class clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse educational error file formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide ideas image infinite ingres integer intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans openjavafx parameter php problem program programming project recursion repositories scanner scrollbar sell server set sms sort sorting sql sqlserver state storm string sun superclass swing swt threads tree websites windows






