i want to create an application that when i click a button, it open an applet using paint. i want it to when i close the applet, it will go back to the interface with the button without closing the whole programme.
example
firstpage.java:
if(e.getSource = openbutt)
{
graph g= new gragh();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
public graph()
{
public void windowActivated(WindowEvent ev){}
public void windowClosed(WindowEvent ev){}
public void windowClosing(WindowEvent ev){
System.exit(0);
}
public void windowDeactivated(WindowEvent ev){}
public void windowDeiconified(WindowEvent ev){}
public void windowIconified(WindowEvent ev){}
public void windowOpened(WindowEvent ev){}
}
how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
Comments
:
: example
: firstpage.java:
: if(e.getSource = openbutt)
: {
:
: graph g= new gragh();
: }
: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: public graph()
: {
: public void windowActivated(WindowEvent ev){}
: public void windowClosed(WindowEvent ev){}
: public void windowClosing(WindowEvent ev){
: System.exit(0);
: }
: public void windowDeactivated(WindowEvent ev){}
: public void windowDeiconified(WindowEvent ev){}
: public void windowIconified(WindowEvent ev){}
: public void windowOpened(WindowEvent ev){}
: }
: how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
:
:
:
:
Remove the System.Exit() statement would be my guess.
: :
: : example
: : firstpage.java:
: : if(e.getSource = openbutt)
: : {
: :
: : graph g= new gragh();
: : }
: : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : public graph()
: : {
: : public void windowActivated(WindowEvent ev){}
: : public void windowClosed(WindowEvent ev){}
: : public void windowClosing(WindowEvent ev){
: : System.exit(0);
: : }
: : public void windowDeactivated(WindowEvent ev){}
: : public void windowDeiconified(WindowEvent ev){}
: : public void windowIconified(WindowEvent ev){}
: : public void windowOpened(WindowEvent ev){}
: : }
: : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: :
: :
: :
: :
: Remove the System.Exit() statement would be my guess.
:
can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
: : :
: : : example
: : : firstpage.java:
: : : if(e.getSource = openbutt)
: : : {
: : :
: : : graph g= new gragh();
: : : }
: : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : : public graph()
: : : {
: : : public void windowActivated(WindowEvent ev){}
: : : public void windowClosed(WindowEvent ev){}
: : : public void windowClosing(WindowEvent ev){
: : : System.exit(0);
: : : }
: : : public void windowDeactivated(WindowEvent ev){}
: : : public void windowDeiconified(WindowEvent ev){}
: : : public void windowIconified(WindowEvent ev){}
: : : public void windowOpened(WindowEvent ev){}
: : : }
: : : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: : :
: : :
: : :
: : :
: : Remove the System.Exit() statement would be my guess.
: :
:
: can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
:
:
Based on your code, no. Perhaps you need to either show a little more relevant code.
: : : :
: : : : example
: : : : firstpage.java:
: : : : if(e.getSource = openbutt)
: : : : {
: : : :
: : : : graph g= new gragh();
: : : : }
: : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : : : public graph()
: : : : {
: : : : public void windowActivated(WindowEvent ev){}
: : : : public void windowClosed(WindowEvent ev){}
: : : : public void windowClosing(WindowEvent ev){
: : : : System.exit(0);
: : : : }
: : : : public void windowDeactivated(WindowEvent ev){}
: : : : public void windowDeiconified(WindowEvent ev){}
: : : : public void windowIconified(WindowEvent ev){}
: : : : public void windowOpened(WindowEvent ev){}
: : : : }
: : : : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: : : :
: : : :
: : : :
: : : :
: : : Remove the System.Exit() statement would be my guess.
: : :
: :
: : can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
: :
: :
: Based on your code, no. Perhaps you need to either show a little more relevant code.
:
import java.awt.*;
import java.applet.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
public class FinalResult extends Frame implements WindowListener
{
static int[] q=new int[80000];
static int[] a=new int[80000];
static int[] x=new int[80000];
static int[] y=new int[80000];
static int[] dp=new int[80000];
static int[] d2=new int[80000];
static int[] d3=new int[80000];
static int[] d4=new int[80000];
static int[] p=new int[80000];
int index=0;
public void windowActivated(WindowEvent ev){}
public void windowClosed(WindowEvent ev){}
public void windowClosing(WindowEvent ev){
//here is 1 exit
System.exit(0);
}
public void windowDeactivated(WindowEvent ev){}
public void windowDeiconified(WindowEvent ev){}
public void windowIconified(WindowEvent ev){}
public void windowOpened(WindowEvent ev){}
public void readData() throws IOException
{
String currentDirectoryPath = new String();
currentDirectoryPath = "C://Java//jwintab01//result//";
JFileChooser fileChooser = new JFileChooser( currentDirectoryPath);
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showOpenDialog(null);
if(result == JFileChooser.CANCEL_OPTION)
System.exit(0);
//here is the 2nd exit.
File fileName = fileChooser.getSelectedFile();
FileInputStream fileInputStream = new FileInputStream(fileName);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
// reading the 1st row of text file
String sentence = bufferedReader.readLine();
// setting the minimum and maximum values to 1st row of text file
StringTokenizer tokenizer = new StringTokenizer(sentence, " ");
q[index] = Integer.parseInt(tokenizer.nextToken());
a[index] = Integer.parseInt(tokenizer.nextToken());
x[index]=Integer.parseInt(tokenizer.nextToken());
y[index]=Integer.parseInt(tokenizer.nextToken());
dp[index] = Integer.parseInt(tokenizer.nextToken());
d2[index] = Integer.parseInt(tokenizer.nextToken());
d3[index]=Integer.parseInt(tokenizer.nextToken());
d4[index]=Integer.parseInt(tokenizer.nextToken());
p[index]=Integer.parseInt(tokenizer.nextToken());
// reading 2nd row of text file
sentence = bufferedReader.readLine();
index=index+1;
// check to make sure current row is not the end of file
while (sentence != null) {
tokenizer = new StringTokenizer(sentence, " ");
// check to make sure that current row is not empty
if (tokenizer.hasMoreTokens()) {
// read in values from current row and set them as max or min values if necessary
q[index] = Integer.parseInt(tokenizer.nextToken());
a[index] = Integer.parseInt(tokenizer.nextToken());
x[index]=Integer.parseInt(tokenizer.nextToken());
y[index]=Integer.parseInt(tokenizer.nextToken());
dp[index] = Integer.parseInt(tokenizer.nextToken());
d2[index] = Integer.parseInt(tokenizer.nextToken());
d3[index]=Integer.parseInt(tokenizer.nextToken());
d4[index]=Integer.parseInt(tokenizer.nextToken());
p[index]=Integer.parseInt(tokenizer.nextToken());
index=index+1;
}
// read next row of text file; returns null if end of file reached
sentence = bufferedReader.readLine();
}
}
public void paint(Graphics g)
{
setBackground(Color.black);
//draw line of zones
setForeground(Color.white);
//big spiral
double e=1;
for(double q=180;q<700;q++)
{
double xaxis, yaxis;
int xax, yax;
xaxis = e * Math.cos(q/100*Math.PI)+270;
yaxis = e * Math.sin(q/100*Math.PI)+505;
e=e-0.5;
xax= (int)(xaxis);
yax= (int)(yaxis);
if(yax<325)
{
g.drawOval(xax,(425-(yax-325)),2,2);
}
else
{
g.drawOval(xax,(425+(325-(yax))),2,2);
}
}
for(int i=0; i<1000; i++)
{
g.setColor( Color.yellow);
if((x[i]!=0)&&(y[i]!=0))
{
g.drawOval(x[i],y[i],5,5);
}
}
}
public FinalResult() throws IOException
{
addWindowListener(this);
setSize(600,580);
setVisible(true);
}
public static void main(String args[]) throws IOException
{
FinalResult g=new FinalResult();
g.readData();
g.repaint();
}
}
i wonder if i can use close(), but inside close() i have to put System.exit also?
: : : : :
: : : : : example
: : : : : firstpage.java:
: : : : : if(e.getSource = openbutt)
: : : : : {
: : : : :
: : : : : graph g= new gragh();
: : : : : }
: : : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : : : : public graph()
: : : : : {
: : : : : public void windowActivated(WindowEvent ev){}
: : : : : public void windowClosed(WindowEvent ev){}
: : : : : public void windowClosing(WindowEvent ev){
: : : : : System.exit(0);
: : : : : }
: : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : public void windowIconified(WindowEvent ev){}
: : : : : public void windowOpened(WindowEvent ev){}
: : : : : }
: : : : : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: : : : :
: : : : :
: : : : :
: : : : :
: : : : Remove the System.Exit() statement would be my guess.
: : : :
: : :
: : : can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
: : :
: : :
: : Based on your code, no. Perhaps you need to either show a little more relevant code.
: :
:
: import java.awt.*;
: import java.applet.*;
: import java.io.*;
: import java.util.*;
: import java.awt.event.*;
: import javax.swing.*;
:
: public class FinalResult extends Frame implements WindowListener
: {
: static int[] q=new int[80000];
: static int[] a=new int[80000];
: static int[] x=new int[80000];
: static int[] y=new int[80000];
: static int[] dp=new int[80000];
: static int[] d2=new int[80000];
: static int[] d3=new int[80000];
: static int[] d4=new int[80000];
: static int[] p=new int[80000];
: int index=0;
:
: public void windowActivated(WindowEvent ev){}
: public void windowClosed(WindowEvent ev){}
: public void windowClosing(WindowEvent ev){
: //here is 1 exit
: System.exit(0);
: }
: public void windowDeactivated(WindowEvent ev){}
: public void windowDeiconified(WindowEvent ev){}
: public void windowIconified(WindowEvent ev){}
: public void windowOpened(WindowEvent ev){}
:
:
: public void readData() throws IOException
: {
: String currentDirectoryPath = new String();
: currentDirectoryPath = "C://Java//jwintab01//result//";
: JFileChooser fileChooser = new JFileChooser( currentDirectoryPath);
:
: fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
: int result = fileChooser.showOpenDialog(null);
: if(result == JFileChooser.CANCEL_OPTION)
: System.exit(0);
: //here is the 2nd exit.
: File fileName = fileChooser.getSelectedFile();
:
:
: FileInputStream fileInputStream = new FileInputStream(fileName);
: InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
: BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
:
: // reading the 1st row of text file
: String sentence = bufferedReader.readLine();
:
: // setting the minimum and maximum values to 1st row of text file
: StringTokenizer tokenizer = new StringTokenizer(sentence, " ");
: q[index] = Integer.parseInt(tokenizer.nextToken());
: a[index] = Integer.parseInt(tokenizer.nextToken());
: x[index]=Integer.parseInt(tokenizer.nextToken());
: y[index]=Integer.parseInt(tokenizer.nextToken());
: dp[index] = Integer.parseInt(tokenizer.nextToken());
: d2[index] = Integer.parseInt(tokenizer.nextToken());
: d3[index]=Integer.parseInt(tokenizer.nextToken());
: d4[index]=Integer.parseInt(tokenizer.nextToken());
: p[index]=Integer.parseInt(tokenizer.nextToken());
:
:
:
: // reading 2nd row of text file
: sentence = bufferedReader.readLine();
:
:
:
: index=index+1;
:
:
: // check to make sure current row is not the end of file
: while (sentence != null) {
: tokenizer = new StringTokenizer(sentence, " ");
:
: // check to make sure that current row is not empty
: if (tokenizer.hasMoreTokens()) {
: // read in values from current row and set them as max or min values if necessary
: q[index] = Integer.parseInt(tokenizer.nextToken());
: a[index] = Integer.parseInt(tokenizer.nextToken());
: x[index]=Integer.parseInt(tokenizer.nextToken());
: y[index]=Integer.parseInt(tokenizer.nextToken());
: dp[index] = Integer.parseInt(tokenizer.nextToken());
: d2[index] = Integer.parseInt(tokenizer.nextToken());
: d3[index]=Integer.parseInt(tokenizer.nextToken());
: d4[index]=Integer.parseInt(tokenizer.nextToken());
: p[index]=Integer.parseInt(tokenizer.nextToken());
:
: index=index+1;
:
: }
:
:
: // read next row of text file; returns null if end of file reached
: sentence = bufferedReader.readLine();
: }
:
:
:
: }
:
:
: public void paint(Graphics g)
: {
: setBackground(Color.black);
:
: //draw line of zones
: setForeground(Color.white);
:
: //big spiral
: double e=1;
: for(double q=180;q<700;q++)
: {
: double xaxis, yaxis;
: int xax, yax;
:
: xaxis = e * Math.cos(q/100*Math.PI)+270;
: yaxis = e * Math.sin(q/100*Math.PI)+505;
: e=e-0.5;
: xax= (int)(xaxis);
: yax= (int)(yaxis);
: if(yax<325)
: {
: g.drawOval(xax,(425-(yax-325)),2,2);
: }
: else
: {
: g.drawOval(xax,(425+(325-(yax))),2,2);
: }
: }
:
:
:
:
: for(int i=0; i<1000; i++)
: {
: g.setColor( Color.yellow);
: if((x[i]!=0)&&(y[i]!=0))
: {
:
: g.drawOval(x[i],y[i],5,5);
: }
: }
: }
:
: public FinalResult() throws IOException
: {
:
:
: addWindowListener(this);
: setSize(600,580);
: setVisible(true);
: }
:
: public static void main(String args[]) throws IOException
: {
:
:
: FinalResult g=new FinalResult();
: g.readData();
: g.repaint();
:
:
:
: }
: }
:
:
: i wonder if i can use close(), but inside close() i have to put System.exit also?
:
:
:
You need to link the WindowListener implementation to the frame using addWindowListener(). See this site for more info: http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
: : : : : :
: : : : : : example
: : : : : : firstpage.java:
: : : : : : if(e.getSource = openbutt)
: : : : : : {
: : : : : :
: : : : : : graph g= new gragh();
: : : : : : }
: : : : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : : : : : public graph()
: : : : : : {
: : : : : : public void windowActivated(WindowEvent ev){}
: : : : : : public void windowClosed(WindowEvent ev){}
: : : : : : public void windowClosing(WindowEvent ev){
: : : : : : System.exit(0);
: : : : : : }
: : : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : : public void windowIconified(WindowEvent ev){}
: : : : : : public void windowOpened(WindowEvent ev){}
: : : : : : }
: : : : : : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : Remove the System.Exit() statement would be my guess.
: : : : :
: : : :
: : : : can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
: : : :
: : : :
: : : Based on your code, no. Perhaps you need to either show a little more relevant code.
: : :
: :
: : import java.awt.*;
: : import java.applet.*;
: : import java.io.*;
: : import java.util.*;
: : import java.awt.event.*;
: : import javax.swing.*;
: :
: : public class FinalResult extends Frame implements WindowListener
: : {
: : static int[] q=new int[80000];
: : static int[] a=new int[80000];
: : static int[] x=new int[80000];
: : static int[] y=new int[80000];
: : static int[] dp=new int[80000];
: : static int[] d2=new int[80000];
: : static int[] d3=new int[80000];
: : static int[] d4=new int[80000];
: : static int[] p=new int[80000];
: : int index=0;
: :
: : public void windowActivated(WindowEvent ev){}
: : public void windowClosed(WindowEvent ev){}
: : public void windowClosing(WindowEvent ev){
: : //here is 1 exit
: : System.exit(0);
: : }
: : public void windowDeactivated(WindowEvent ev){}
: : public void windowDeiconified(WindowEvent ev){}
: : public void windowIconified(WindowEvent ev){}
: : public void windowOpened(WindowEvent ev){}
: :
: :
: : public void readData() throws IOException
: : {
: : String currentDirectoryPath = new String();
: : currentDirectoryPath = "C://Java//jwintab01//result//";
: : JFileChooser fileChooser = new JFileChooser( currentDirectoryPath);
: :
: : fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
: : int result = fileChooser.showOpenDialog(null);
: : if(result == JFileChooser.CANCEL_OPTION)
: : System.exit(0);
: : //here is the 2nd exit.
: : File fileName = fileChooser.getSelectedFile();
: :
: :
: : FileInputStream fileInputStream = new FileInputStream(fileName);
: : InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
: : BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
: :
: : // reading the 1st row of text file
: : String sentence = bufferedReader.readLine();
: :
: : // setting the minimum and maximum values to 1st row of text file
: : StringTokenizer tokenizer = new StringTokenizer(sentence, " ");
: : q[index] = Integer.parseInt(tokenizer.nextToken());
: : a[index] = Integer.parseInt(tokenizer.nextToken());
: : x[index]=Integer.parseInt(tokenizer.nextToken());
: : y[index]=Integer.parseInt(tokenizer.nextToken());
: : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : p[index]=Integer.parseInt(tokenizer.nextToken());
: :
: :
: :
: : // reading 2nd row of text file
: : sentence = bufferedReader.readLine();
: :
: :
: :
: : index=index+1;
: :
: :
: : // check to make sure current row is not the end of file
: : while (sentence != null) {
: : tokenizer = new StringTokenizer(sentence, " ");
: :
: : // check to make sure that current row is not empty
: : if (tokenizer.hasMoreTokens()) {
: : // read in values from current row and set them as max or min values if necessary
: : q[index] = Integer.parseInt(tokenizer.nextToken());
: : a[index] = Integer.parseInt(tokenizer.nextToken());
: : x[index]=Integer.parseInt(tokenizer.nextToken());
: : y[index]=Integer.parseInt(tokenizer.nextToken());
: : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : p[index]=Integer.parseInt(tokenizer.nextToken());
: :
: : index=index+1;
: :
: : }
: :
: :
: : // read next row of text file; returns null if end of file reached
: : sentence = bufferedReader.readLine();
: : }
: :
: :
: :
: : }
: :
: :
: : public void paint(Graphics g)
: : {
: : setBackground(Color.black);
: :
: : //draw line of zones
: : setForeground(Color.white);
: :
: : //big spiral
: : double e=1;
: : for(double q=180;q<700;q++)
: : {
: : double xaxis, yaxis;
: : int xax, yax;
: :
: : xaxis = e * Math.cos(q/100*Math.PI)+270;
: : yaxis = e * Math.sin(q/100*Math.PI)+505;
: : e=e-0.5;
: : xax= (int)(xaxis);
: : yax= (int)(yaxis);
: : if(yax<325)
: : {
: : g.drawOval(xax,(425-(yax-325)),2,2);
: : }
: : else
: : {
: : g.drawOval(xax,(425+(325-(yax))),2,2);
: : }
: : }
: :
: :
: :
: :
: : for(int i=0; i<1000; i++)
: : {
: : g.setColor( Color.yellow);
: : if((x[i]!=0)&&(y[i]!=0))
: : {
: :
: : g.drawOval(x[i],y[i],5,5);
: : }
: : }
: : }
: :
: : public FinalResult() throws IOException
: : {
: :
: :
: : addWindowListener(this);
: : setSize(600,580);
: : setVisible(true);
: : }
: :
: : public static void main(String args[]) throws IOException
: : {
: :
: :
: : FinalResult g=new FinalResult();
: : g.readData();
: : g.repaint();
: :
: :
: :
: : }
: : }
: :
: :
: : i wonder if i can use close(), but inside close() i have to put System.exit also?
: :
: :
: :
: You need to link the WindowListener implementation to the frame using addWindowListener(). See this site for more info: http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
:
i still dont understand.
is it that i have to create a frame and add
public void windowClosing(WindowEvent e) {
ActionListener task = new ActionListener() {
boolean alreadyDisposed = false;
public void actionPerformed(ActionEvent e) {
if (!alreadyDisposed) {
alreadyDisposed = true;
frame.dispose();
} else {
System.exit(0);
}
}
};
}
but after adding it, i didnt get any error when i compile but when i try to run it, it says there is a NullPointerException.
: : : : : : :
: : : : : : : example
: : : : : : : firstpage.java:
: : : : : : : if(e.getSource = openbutt)
: : : : : : : {
: : : : : : :
: : : : : : : graph g= new gragh();
: : : : : : : }
: : : : : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : : : : : : public graph()
: : : : : : : {
: : : : : : : public void windowActivated(WindowEvent ev){}
: : : : : : : public void windowClosed(WindowEvent ev){}
: : : : : : : public void windowClosing(WindowEvent ev){
: : : : : : : System.exit(0);
: : : : : : : }
: : : : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : : : public void windowIconified(WindowEvent ev){}
: : : : : : : public void windowOpened(WindowEvent ev){}
: : : : : : : }
: : : : : : : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : Remove the System.Exit() statement would be my guess.
: : : : : :
: : : : :
: : : : : can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
: : : : :
: : : : :
: : : : Based on your code, no. Perhaps you need to either show a little more relevant code.
: : : :
: : :
: : : import java.awt.*;
: : : import java.applet.*;
: : : import java.io.*;
: : : import java.util.*;
: : : import java.awt.event.*;
: : : import javax.swing.*;
: : :
: : : public class FinalResult extends Frame implements WindowListener
: : : {
: : : static int[] q=new int[80000];
: : : static int[] a=new int[80000];
: : : static int[] x=new int[80000];
: : : static int[] y=new int[80000];
: : : static int[] dp=new int[80000];
: : : static int[] d2=new int[80000];
: : : static int[] d3=new int[80000];
: : : static int[] d4=new int[80000];
: : : static int[] p=new int[80000];
: : : int index=0;
: : :
: : : public void windowActivated(WindowEvent ev){}
: : : public void windowClosed(WindowEvent ev){}
: : : public void windowClosing(WindowEvent ev){
: : : //here is 1 exit
: : : System.exit(0);
: : : }
: : : public void windowDeactivated(WindowEvent ev){}
: : : public void windowDeiconified(WindowEvent ev){}
: : : public void windowIconified(WindowEvent ev){}
: : : public void windowOpened(WindowEvent ev){}
: : :
: : :
: : : public void readData() throws IOException
: : : {
: : : String currentDirectoryPath = new String();
: : : currentDirectoryPath = "C://Java//jwintab01//result//";
: : : JFileChooser fileChooser = new JFileChooser( currentDirectoryPath);
: : :
: : : fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
: : : int result = fileChooser.showOpenDialog(null);
: : : if(result == JFileChooser.CANCEL_OPTION)
: : : System.exit(0);
: : : //here is the 2nd exit.
: : : File fileName = fileChooser.getSelectedFile();
: : :
: : :
: : : FileInputStream fileInputStream = new FileInputStream(fileName);
: : : InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
: : : BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
: : :
: : : // reading the 1st row of text file
: : : String sentence = bufferedReader.readLine();
: : :
: : : // setting the minimum and maximum values to 1st row of text file
: : : StringTokenizer tokenizer = new StringTokenizer(sentence, " ");
: : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : :
: : :
: : :
: : : // reading 2nd row of text file
: : : sentence = bufferedReader.readLine();
: : :
: : :
: : :
: : : index=index+1;
: : :
: : :
: : : // check to make sure current row is not the end of file
: : : while (sentence != null) {
: : : tokenizer = new StringTokenizer(sentence, " ");
: : :
: : : // check to make sure that current row is not empty
: : : if (tokenizer.hasMoreTokens()) {
: : : // read in values from current row and set them as max or min values if necessary
: : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : :
: : : index=index+1;
: : :
: : : }
: : :
: : :
: : : // read next row of text file; returns null if end of file reached
: : : sentence = bufferedReader.readLine();
: : : }
: : :
: : :
: : :
: : : }
: : :
: : :
: : : public void paint(Graphics g)
: : : {
: : : setBackground(Color.black);
: : :
: : : //draw line of zones
: : : setForeground(Color.white);
: : :
: : : //big spiral
: : : double e=1;
: : : for(double q=180;q<700;q++)
: : : {
: : : double xaxis, yaxis;
: : : int xax, yax;
: : :
: : : xaxis = e * Math.cos(q/100*Math.PI)+270;
: : : yaxis = e * Math.sin(q/100*Math.PI)+505;
: : : e=e-0.5;
: : : xax= (int)(xaxis);
: : : yax= (int)(yaxis);
: : : if(yax<325)
: : : {
: : : g.drawOval(xax,(425-(yax-325)),2,2);
: : : }
: : : else
: : : {
: : : g.drawOval(xax,(425+(325-(yax))),2,2);
: : : }
: : : }
: : :
: : :
: : :
: : :
: : : for(int i=0; i<1000; i++)
: : : {
: : : g.setColor( Color.yellow);
: : : if((x[i]!=0)&&(y[i]!=0))
: : : {
: : :
: : : g.drawOval(x[i],y[i],5,5);
: : : }
: : : }
: : : }
: : :
: : : public FinalResult() throws IOException
: : : {
: : :
: : :
: : : addWindowListener(this);
: : : setSize(600,580);
: : : setVisible(true);
: : : }
: : :
: : : public static void main(String args[]) throws IOException
: : : {
: : :
: : :
: : : FinalResult g=new FinalResult();
: : : g.readData();
: : : g.repaint();
: : :
: : :
: : :
: : : }
: : : }
: : :
: : :
: : : i wonder if i can use close(), but inside close() i have to put System.exit also?
: : :
: : :
: : :
: : You need to link the WindowListener implementation to the frame using addWindowListener(). See this site for more info: http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
: :
:
:
: i still dont understand.
: is it that i have to create a frame and add
: public void windowClosing(WindowEvent e) {
: ActionListener task = new ActionListener() {
: boolean alreadyDisposed = false;
: public void actionPerformed(ActionEvent e) {
: if (!alreadyDisposed) {
: alreadyDisposed = true;
: frame.dispose();
: } else {
: System.exit(0);
: }
: }
: };
: }
:
: but after adding it, i didnt get any error when i compile but when i try to run it, it says there is a NullPointerException.
:
:
Give the following code:
[code]
class Closer1 implements WindListener
{
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
}
class Closer2 implements WindListener
{
public void windowClosing(WindowEvent ev) {
SaveDataToFile();
}
}
class Closer3 implements WindListener
{
public void windowClosing(WindowEvent ev) {
System.exit(1);
}
}
class MyFrame extends JFrame
{
public MyFrame
{
}
}
[/code]
Which Closer object is used as WindowListener implementation?
: : : : : : : :
: : : : : : : : example
: : : : : : : : firstpage.java:
: : : : : : : : if(e.getSource = openbutt)
: : : : : : : : {
: : : : : : : :
: : : : : : : : graph g= new gragh();
: : : : : : : : }
: : : : : : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : : : : : : : public graph()
: : : : : : : : {
: : : : : : : : public void windowActivated(WindowEvent ev){}
: : : : : : : : public void windowClosed(WindowEvent ev){}
: : : : : : : : public void windowClosing(WindowEvent ev){
: : : : : : : : System.exit(0);
: : : : : : : : }
: : : : : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : : : : public void windowIconified(WindowEvent ev){}
: : : : : : : : public void windowOpened(WindowEvent ev){}
: : : : : : : : }
: : : : : : : : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: : : : : : : :
: : : : : : : :
: : : : : : : :
: : : : : : : :
: : : : : : : Remove the System.Exit() statement would be my guess.
: : : : : : :
: : : : : :
: : : : : : can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
: : : : : :
: : : : : :
: : : : : Based on your code, no. Perhaps you need to either show a little more relevant code.
: : : : :
: : : :
: : : : import java.awt.*;
: : : : import java.applet.*;
: : : : import java.io.*;
: : : : import java.util.*;
: : : : import java.awt.event.*;
: : : : import javax.swing.*;
: : : :
: : : : public class FinalResult extends Frame implements WindowListener
: : : : {
: : : : static int[] q=new int[80000];
: : : : static int[] a=new int[80000];
: : : : static int[] x=new int[80000];
: : : : static int[] y=new int[80000];
: : : : static int[] dp=new int[80000];
: : : : static int[] d2=new int[80000];
: : : : static int[] d3=new int[80000];
: : : : static int[] d4=new int[80000];
: : : : static int[] p=new int[80000];
: : : : int index=0;
: : : :
: : : : public void windowActivated(WindowEvent ev){}
: : : : public void windowClosed(WindowEvent ev){}
: : : : public void windowClosing(WindowEvent ev){
: : : : //here is 1 exit
: : : : System.exit(0);
: : : : }
: : : : public void windowDeactivated(WindowEvent ev){}
: : : : public void windowDeiconified(WindowEvent ev){}
: : : : public void windowIconified(WindowEvent ev){}
: : : : public void windowOpened(WindowEvent ev){}
: : : :
: : : :
: : : : public void readData() throws IOException
: : : : {
: : : : String currentDirectoryPath = new String();
: : : : currentDirectoryPath = "C://Java//jwintab01//result//";
: : : : JFileChooser fileChooser = new JFileChooser( currentDirectoryPath);
: : : :
: : : : fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
: : : : int result = fileChooser.showOpenDialog(null);
: : : : if(result == JFileChooser.CANCEL_OPTION)
: : : : System.exit(0);
: : : : //here is the 2nd exit.
: : : : File fileName = fileChooser.getSelectedFile();
: : : :
: : : :
: : : : FileInputStream fileInputStream = new FileInputStream(fileName);
: : : : InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
: : : : BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
: : : :
: : : : // reading the 1st row of text file
: : : : String sentence = bufferedReader.readLine();
: : : :
: : : : // setting the minimum and maximum values to 1st row of text file
: : : : StringTokenizer tokenizer = new StringTokenizer(sentence, " ");
: : : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : : :
: : : :
: : : :
: : : : // reading 2nd row of text file
: : : : sentence = bufferedReader.readLine();
: : : :
: : : :
: : : :
: : : : index=index+1;
: : : :
: : : :
: : : : // check to make sure current row is not the end of file
: : : : while (sentence != null) {
: : : : tokenizer = new StringTokenizer(sentence, " ");
: : : :
: : : : // check to make sure that current row is not empty
: : : : if (tokenizer.hasMoreTokens()) {
: : : : // read in values from current row and set them as max or min values if necessary
: : : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : : :
: : : : index=index+1;
: : : :
: : : : }
: : : :
: : : :
: : : : // read next row of text file; returns null if end of file reached
: : : : sentence = bufferedReader.readLine();
: : : : }
: : : :
: : : :
: : : :
: : : : }
: : : :
: : : :
: : : : public void paint(Graphics g)
: : : : {
: : : : setBackground(Color.black);
: : : :
: : : : //draw line of zones
: : : : setForeground(Color.white);
: : : :
: : : : //big spiral
: : : : double e=1;
: : : : for(double q=180;q<700;q++)
: : : : {
: : : : double xaxis, yaxis;
: : : : int xax, yax;
: : : :
: : : : xaxis = e * Math.cos(q/100*Math.PI)+270;
: : : : yaxis = e * Math.sin(q/100*Math.PI)+505;
: : : : e=e-0.5;
: : : : xax= (int)(xaxis);
: : : : yax= (int)(yaxis);
: : : : if(yax<325)
: : : : {
: : : : g.drawOval(xax,(425-(yax-325)),2,2);
: : : : }
: : : : else
: : : : {
: : : : g.drawOval(xax,(425+(325-(yax))),2,2);
: : : : }
: : : : }
: : : :
: : : :
: : : :
: : : :
: : : : for(int i=0; i<1000; i++)
: : : : {
: : : : g.setColor( Color.yellow);
: : : : if((x[i]!=0)&&(y[i]!=0))
: : : : {
: : : :
: : : : g.drawOval(x[i],y[i],5,5);
: : : : }
: : : : }
: : : : }
: : : :
: : : : public FinalResult() throws IOException
: : : : {
: : : :
: : : :
: : : : addWindowListener(this);
: : : : setSize(600,580);
: : : : setVisible(true);
: : : : }
: : : :
: : : : public static void main(String args[]) throws IOException
: : : : {
: : : :
: : : :
: : : : FinalResult g=new FinalResult();
: : : : g.readData();
: : : : g.repaint();
: : : :
: : : :
: : : :
: : : : }
: : : : }
: : : :
: : : :
: : : : i wonder if i can use close(), but inside close() i have to put System.exit also?
: : : :
: : : :
: : : :
: : : You need to link the WindowListener implementation to the frame using addWindowListener(). See this site for more info: http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
: : :
: :
: :
: : i still dont understand.
: : is it that i have to create a frame and add
: : public void windowClosing(WindowEvent e) {
: : ActionListener task = new ActionListener() {
: : boolean alreadyDisposed = false;
: : public void actionPerformed(ActionEvent e) {
: : if (!alreadyDisposed) {
: : alreadyDisposed = true;
: : frame.dispose();
: : } else {
: : System.exit(0);
: : }
: : }
: : };
: : }
: :
: : but after adding it, i didnt get any error when i compile but when i try to run it, it says there is a NullPointerException.
: :
: :
: Give the following code:
: [code]
: class Closer1 implements WindListener
: {
: public void windowClosing(WindowEvent ev) {
: System.exit(0);
: }
: }
:
: class Closer2 implements WindListener
: {
: public void windowClosing(WindowEvent ev) {
: SaveDataToFile();
: }
: }
:
: class Closer3 implements WindListener
: {
: public void windowClosing(WindowEvent ev) {
: System.exit(1);
: }
: }
:
: class MyFrame extends JFrame
: {
: public MyFrame
: {
: }
: }
: [/code]
: Which Closer object is used as WindowListener implementation?
:
actually system.exit(0) or (1) make no diff right?
so you saying i have to create another class for the exit?
: : : : : : : : :
: : : : : : : : : example
: : : : : : : : : firstpage.java:
: : : : : : : : : if(e.getSource = openbutt)
: : : : : : : : : {
: : : : : : : : :
: : : : : : : : : graph g= new gragh();
: : : : : : : : : }
: : : : : : : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : : : : : : : : public graph()
: : : : : : : : : {
: : : : : : : : : public void windowActivated(WindowEvent ev){}
: : : : : : : : : public void windowClosed(WindowEvent ev){}
: : : : : : : : : public void windowClosing(WindowEvent ev){
: : : : : : : : : System.exit(0);
: : : : : : : : : }
: : : : : : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : : : : : public void windowIconified(WindowEvent ev){}
: : : : : : : : : public void windowOpened(WindowEvent ev){}
: : : : : : : : : }
: : : : : : : : : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: : : : : : : : :
: : : : : : : : :
: : : : : : : : :
: : : : : : : : :
: : : : : : : : Remove the System.Exit() statement would be my guess.
: : : : : : : :
: : : : : : :
: : : : : : : can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
: : : : : : :
: : : : : : :
: : : : : : Based on your code, no. Perhaps you need to either show a little more relevant code.
: : : : : :
: : : : :
: : : : : import java.awt.*;
: : : : : import java.applet.*;
: : : : : import java.io.*;
: : : : : import java.util.*;
: : : : : import java.awt.event.*;
: : : : : import javax.swing.*;
: : : : :
: : : : : public class FinalResult extends Frame implements WindowListener
: : : : : {
: : : : : static int[] q=new int[80000];
: : : : : static int[] a=new int[80000];
: : : : : static int[] x=new int[80000];
: : : : : static int[] y=new int[80000];
: : : : : static int[] dp=new int[80000];
: : : : : static int[] d2=new int[80000];
: : : : : static int[] d3=new int[80000];
: : : : : static int[] d4=new int[80000];
: : : : : static int[] p=new int[80000];
: : : : : int index=0;
: : : : :
: : : : : public void windowActivated(WindowEvent ev){}
: : : : : public void windowClosed(WindowEvent ev){}
: : : : : public void windowClosing(WindowEvent ev){
: : : : : //here is 1 exit
: : : : : System.exit(0);
: : : : : }
: : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : public void windowIconified(WindowEvent ev){}
: : : : : public void windowOpened(WindowEvent ev){}
: : : : :
: : : : :
: : : : : public void readData() throws IOException
: : : : : {
: : : : : String currentDirectoryPath = new String();
: : : : : currentDirectoryPath = "C://Java//jwintab01//result//";
: : : : : JFileChooser fileChooser = new JFileChooser( currentDirectoryPath);
: : : : :
: : : : : fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
: : : : : int result = fileChooser.showOpenDialog(null);
: : : : : if(result == JFileChooser.CANCEL_OPTION)
: : : : : System.exit(0);
: : : : : //here is the 2nd exit.
: : : : : File fileName = fileChooser.getSelectedFile();
: : : : :
: : : : :
: : : : : FileInputStream fileInputStream = new FileInputStream(fileName);
: : : : : InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
: : : : : BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
: : : : :
: : : : : // reading the 1st row of text file
: : : : : String sentence = bufferedReader.readLine();
: : : : :
: : : : : // setting the minimum and maximum values to 1st row of text file
: : : : : StringTokenizer tokenizer = new StringTokenizer(sentence, " ");
: : : : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : : : :
: : : : :
: : : : :
: : : : : // reading 2nd row of text file
: : : : : sentence = bufferedReader.readLine();
: : : : :
: : : : :
: : : : :
: : : : : index=index+1;
: : : : :
: : : : :
: : : : : // check to make sure current row is not the end of file
: : : : : while (sentence != null) {
: : : : : tokenizer = new StringTokenizer(sentence, " ");
: : : : :
: : : : : // check to make sure that current row is not empty
: : : : : if (tokenizer.hasMoreTokens()) {
: : : : : // read in values from current row and set them as max or min values if necessary
: : : : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : : : :
: : : : : index=index+1;
: : : : :
: : : : : }
: : : : :
: : : : :
: : : : : // read next row of text file; returns null if end of file reached
: : : : : sentence = bufferedReader.readLine();
: : : : : }
: : : : :
: : : : :
: : : : :
: : : : : }
: : : : :
: : : : :
: : : : : public void paint(Graphics g)
: : : : : {
: : : : : setBackground(Color.black);
: : : : :
: : : : : //draw line of zones
: : : : : setForeground(Color.white);
: : : : :
: : : : : //big spiral
: : : : : double e=1;
: : : : : for(double q=180;q<700;q++)
: : : : : {
: : : : : double xaxis, yaxis;
: : : : : int xax, yax;
: : : : :
: : : : : xaxis = e * Math.cos(q/100*Math.PI)+270;
: : : : : yaxis = e * Math.sin(q/100*Math.PI)+505;
: : : : : e=e-0.5;
: : : : : xax= (int)(xaxis);
: : : : : yax= (int)(yaxis);
: : : : : if(yax<325)
: : : : : {
: : : : : g.drawOval(xax,(425-(yax-325)),2,2);
: : : : : }
: : : : : else
: : : : : {
: : : : : g.drawOval(xax,(425+(325-(yax))),2,2);
: : : : : }
: : : : : }
: : : : :
: : : : :
: : : : :
: : : : :
: : : : : for(int i=0; i<1000; i++)
: : : : : {
: : : : : g.setColor( Color.yellow);
: : : : : if((x[i]!=0)&&(y[i]!=0))
: : : : : {
: : : : :
: : : : : g.drawOval(x[i],y[i],5,5);
: : : : : }
: : : : : }
: : : : : }
: : : : :
: : : : : public FinalResult() throws IOException
: : : : : {
: : : : :
: : : : :
: : : : : addWindowListener(this);
: : : : : setSize(600,580);
: : : : : setVisible(true);
: : : : : }
: : : : :
: : : : : public static void main(String args[]) throws IOException
: : : : : {
: : : : :
: : : : :
: : : : : FinalResult g=new FinalResult();
: : : : : g.readData();
: : : : : g.repaint();
: : : : :
: : : : :
: : : : :
: : : : : }
: : : : : }
: : : : :
: : : : :
: : : : : i wonder if i can use close(), but inside close() i have to put System.exit also?
: : : : :
: : : : :
: : : : :
: : : : You need to link the WindowListener implementation to the frame using addWindowListener(). See this site for more info: http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
: : : :
: : :
: : :
: : : i still dont understand.
: : : is it that i have to create a frame and add
: : : public void windowClosing(WindowEvent e) {
: : : ActionListener task = new ActionListener() {
: : : boolean alreadyDisposed = false;
: : : public void actionPerformed(ActionEvent e) {
: : : if (!alreadyDisposed) {
: : : alreadyDisposed = true;
: : : frame.dispose();
: : : } else {
: : : System.exit(0);
: : : }
: : : }
: : : };
: : : }
: : :
: : : but after adding it, i didnt get any error when i compile but when i try to run it, it says there is a NullPointerException.
: : :
: : :
: : Give the following code:
: : [code]
: : class Closer1 implements WindListener
: : {
: : public void windowClosing(WindowEvent ev) {
: : System.exit(0);
: : }
: : }
: :
: : class Closer2 implements WindListener
: : {
: : public void windowClosing(WindowEvent ev) {
: : SaveDataToFile();
: : }
: : }
: :
: : class Closer3 implements WindListener
: : {
: : public void windowClosing(WindowEvent ev) {
: : System.exit(1);
: : }
: : }
: :
: : class MyFrame extends JFrame
: : {
: : public MyFrame
: : {
: : }
: : }
: : [/code]
: : Which Closer object is used as WindowListener implementation?
: :
: actually system.exit(0) or (1) make no diff right?
: so you saying i have to create another class for the exit?
:
:
None are run, because the window doesn't know which to run. The following addition to the frame code specifies which Closer is run:
[code]
class MyFrame extends JFrame
{
public MyFrame
{
this.addWindowListener(new Closer1());
}
}
[/code]
Now the frame will run the windowClosing() method in the Closer1 class. This crucial line (addWindowListener) is missing in your code.
As for the difference between Exit(0) and Exit(1), there is a difference to the process, which executes the application. It indicates the DOS ERRORLEVEL.
: : : : : : : : : :
: : : : : : : : : : example
: : : : : : : : : : firstpage.java:
: : : : : : : : : : if(e.getSource = openbutt)
: : : : : : : : : : {
: : : : : : : : : :
: : : : : : : : : : graph g= new gragh();
: : : : : : : : : : }
: : : : : : : : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : : : : : : : : : public graph()
: : : : : : : : : : {
: : : : : : : : : : public void windowActivated(WindowEvent ev){}
: : : : : : : : : : public void windowClosed(WindowEvent ev){}
: : : : : : : : : : public void windowClosing(WindowEvent ev){
: : : : : : : : : : System.exit(0);
: : : : : : : : : : }
: : : : : : : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : : : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : : : : : : public void windowIconified(WindowEvent ev){}
: : : : : : : : : : public void windowOpened(WindowEvent ev){}
: : : : : : : : : : }
: : : : : : : : : : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: : : : : : : : : :
: : : : : : : : : :
: : : : : : : : : :
: : : : : : : : : :
: : : : : : : : : Remove the System.Exit() statement would be my guess.
: : : : : : : : :
: : : : : : : :
: : : : : : : : can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
: : : : : : : :
: : : : : : : :
: : : : : : : Based on your code, no. Perhaps you need to either show a little more relevant code.
: : : : : : :
: : : : : :
: : : : : : import java.awt.*;
: : : : : : import java.applet.*;
: : : : : : import java.io.*;
: : : : : : import java.util.*;
: : : : : : import java.awt.event.*;
: : : : : : import javax.swing.*;
: : : : : :
: : : : : : public class FinalResult extends Frame implements WindowListener
: : : : : : {
: : : : : : static int[] q=new int[80000];
: : : : : : static int[] a=new int[80000];
: : : : : : static int[] x=new int[80000];
: : : : : : static int[] y=new int[80000];
: : : : : : static int[] dp=new int[80000];
: : : : : : static int[] d2=new int[80000];
: : : : : : static int[] d3=new int[80000];
: : : : : : static int[] d4=new int[80000];
: : : : : : static int[] p=new int[80000];
: : : : : : int index=0;
: : : : : :
: : : : : : public void windowActivated(WindowEvent ev){}
: : : : : : public void windowClosed(WindowEvent ev){}
: : : : : : public void windowClosing(WindowEvent ev){
: : : : : : //here is 1 exit
: : : : : : System.exit(0);
: : : : : : }
: : : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : : public void windowIconified(WindowEvent ev){}
: : : : : : public void windowOpened(WindowEvent ev){}
: : : : : :
: : : : : :
: : : : : : public void readData() throws IOException
: : : : : : {
: : : : : : String currentDirectoryPath = new String();
: : : : : : currentDirectoryPath = "C://Java//jwintab01//result//";
: : : : : : JFileChooser fileChooser = new JFileChooser( currentDirectoryPath);
: : : : : :
: : : : : : fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
: : : : : : int result = fileChooser.showOpenDialog(null);
: : : : : : if(result == JFileChooser.CANCEL_OPTION)
: : : : : : System.exit(0);
: : : : : : //here is the 2nd exit.
: : : : : : File fileName = fileChooser.getSelectedFile();
: : : : : :
: : : : : :
: : : : : : FileInputStream fileInputStream = new FileInputStream(fileName);
: : : : : : InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
: : : : : : BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
: : : : : :
: : : : : : // reading the 1st row of text file
: : : : : : String sentence = bufferedReader.readLine();
: : : : : :
: : : : : : // setting the minimum and maximum values to 1st row of text file
: : : : : : StringTokenizer tokenizer = new StringTokenizer(sentence, " ");
: : : : : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : :
: : : : : :
: : : : : :
: : : : : : // reading 2nd row of text file
: : : : : : sentence = bufferedReader.readLine();
: : : : : :
: : : : : :
: : : : : :
: : : : : : index=index+1;
: : : : : :
: : : : : :
: : : : : : // check to make sure current row is not the end of file
: : : : : : while (sentence != null) {
: : : : : : tokenizer = new StringTokenizer(sentence, " ");
: : : : : :
: : : : : : // check to make sure that current row is not empty
: : : : : : if (tokenizer.hasMoreTokens()) {
: : : : : : // read in values from current row and set them as max or min values if necessary
: : : : : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : :
: : : : : : index=index+1;
: : : : : :
: : : : : : }
: : : : : :
: : : : : :
: : : : : : // read next row of text file; returns null if end of file reached
: : : : : : sentence = bufferedReader.readLine();
: : : : : : }
: : : : : :
: : : : : :
: : : : : :
: : : : : : }
: : : : : :
: : : : : :
: : : : : : public void paint(Graphics g)
: : : : : : {
: : : : : : setBackground(Color.black);
: : : : : :
: : : : : : //draw line of zones
: : : : : : setForeground(Color.white);
: : : : : :
: : : : : : //big spiral
: : : : : : double e=1;
: : : : : : for(double q=180;q<700;q++)
: : : : : : {
: : : : : : double xaxis, yaxis;
: : : : : : int xax, yax;
: : : : : :
: : : : : : xaxis = e * Math.cos(q/100*Math.PI)+270;
: : : : : : yaxis = e * Math.sin(q/100*Math.PI)+505;
: : : : : : e=e-0.5;
: : : : : : xax= (int)(xaxis);
: : : : : : yax= (int)(yaxis);
: : : : : : if(yax<325)
: : : : : : {
: : : : : : g.drawOval(xax,(425-(yax-325)),2,2);
: : : : : : }
: : : : : : else
: : : : : : {
: : : : : : g.drawOval(xax,(425+(325-(yax))),2,2);
: : : : : : }
: : : : : : }
: : : : : :
: : : : : :
: : : : : :
: : : : : :
: : : : : : for(int i=0; i<1000; i++)
: : : : : : {
: : : : : : g.setColor( Color.yellow);
: : : : : : if((x[i]!=0)&&(y[i]!=0))
: : : : : : {
: : : : : :
: : : : : : g.drawOval(x[i],y[i],5,5);
: : : : : : }
: : : : : : }
: : : : : : }
: : : : : :
: : : : : : public FinalResult() throws IOException
: : : : : : {
: : : : : :
: : : : : :
: : : : : : addWindowListener(this);
: : : : : : setSize(600,580);
: : : : : : setVisible(true);
: : : : : : }
: : : : : :
: : : : : : public static void main(String args[]) throws IOException
: : : : : : {
: : : : : :
: : : : : :
: : : : : : FinalResult g=new FinalResult();
: : : : : : g.readData();
: : : : : : g.repaint();
: : : : : :
: : : : : :
: : : : : :
: : : : : : }
: : : : : : }
: : : : : :
: : : : : :
: : : : : : i wonder if i can use close(), but inside close() i have to put System.exit also?
: : : : : :
: : : : : :
: : : : : :
: : : : : You need to link the WindowListener implementation to the frame using addWindowListener(). See this site for more info: http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
: : : : :
: : : :
: : : :
: : : : i still dont understand.
: : : : is it that i have to create a frame and add
: : : : public void windowClosing(WindowEvent e) {
: : : : ActionListener task = new ActionListener() {
: : : : boolean alreadyDisposed = false;
: : : : public void actionPerformed(ActionEvent e) {
: : : : if (!alreadyDisposed) {
: : : : alreadyDisposed = true;
: : : : frame.dispose();
: : : : } else {
: : : : System.exit(0);
: : : : }
: : : : }
: : : : };
: : : : }
: : : :
: : : : but after adding it, i didnt get any error when i compile but when i try to run it, it says there is a NullPointerException.
: : : :
: : : :
: : : Give the following code:
: : : [code]
: : : class Closer1 implements WindListener
: : : {
: : : public void windowClosing(WindowEvent ev) {
: : : System.exit(0);
: : : }
: : : }
: : :
: : : class Closer2 implements WindListener
: : : {
: : : public void windowClosing(WindowEvent ev) {
: : : SaveDataToFile();
: : : }
: : : }
: : :
: : : class Closer3 implements WindListener
: : : {
: : : public void windowClosing(WindowEvent ev) {
: : : System.exit(1);
: : : }
: : : }
: : :
: : : class MyFrame extends JFrame
: : : {
: : : public MyFrame
: : : {
: : : }
: : : }
: : : [/code]
: : : Which Closer object is used as WindowListener implementation?
: : :
: : actually system.exit(0) or (1) make no diff right?
: : so you saying i have to create another class for the exit?
: :
: :
: None are run, because the window doesn't know which to run. The following addition to the frame code specifies which Closer is run:
: [code]
: class MyFrame extends JFrame
: {
: public MyFrame
: {
: this.addWindowListener(new Closer1());
: }
: }
: [/code]
: Now the frame will run the windowClosing() method in the Closer1 class. This crucial line (addWindowListener) is missing in your code.
: As for the difference between Exit(0) and Exit(1), there is a difference to the process, which executes the application. It indicates the DOS ERRORLEVEL.
:
class Closer1 implements WindListener
{
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
}
class MyFrame extends JFrame
{
public MyFrame
{
this.addWindowListener(new Closer1());
}
}
if i were type it this way it will have an error of saying is the Closer1 an abstract or class or interface.
: : : : : : : : : : : i want to create an application that when i click a button, it open an applet using paint. i want it to when i close the applet, it will go back to the interface with the button without closing the whole programme.
: : : : : : : : : : :
: : : : : : : : : : : example
: : : : : : : : : : : firstpage.java:
: : : : : : : : : : : if(e.getSource = openbutt)
: : : : : : : : : : : {
: : : : : : : : : : :
: : : : : : : : : : : graph g= new gragh();
: : : : : : : : : : : }
: : : : : : : : : : : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``
: : : : : : : : : : : public graph()
: : : : : : : : : : : {
: : : : : : : : : : : public void windowActivated(WindowEvent ev){}
: : : : : : : : : : : public void windowClosed(WindowEvent ev){}
: : : : : : : : : : : public void windowClosing(WindowEvent ev){
: : : : : : : : : : : System.exit(0);
: : : : : : : : : : : }
: : : : : : : : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : : : : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : : : : : : : public void windowIconified(WindowEvent ev){}
: : : : : : : : : : : public void windowOpened(WindowEvent ev){}
: : : : : : : : : : : }
: : : : : : : : : : : how can i replace this so that it wouldnt system.exit the whole application when i close the graph. and will go back to firstpage().
: : : : : : : : : : :
: : : : : : : : : : :
: : : : : : : : : : :
: : : : : : : : : : :
: : : : : : : : : : Remove the System.Exit() statement would be my guess.
: : : : : : : : : :
: : : : : : : : :
: : : : : : : : : can't if i were to remove it, when i click the close nothing will happen. i still trying to figure out. do you have anymore ideas? =p
: : : : : : : : :
: : : : : : : : :
: : : : : : : : Based on your code, no. Perhaps you need to either show a little more relevant code.
: : : : : : : :
: : : : : : :
: : : : : : : import java.awt.*;
: : : : : : : import java.applet.*;
: : : : : : : import java.io.*;
: : : : : : : import java.util.*;
: : : : : : : import java.awt.event.*;
: : : : : : : import javax.swing.*;
: : : : : : :
: : : : : : : public class FinalResult extends Frame implements WindowListener
: : : : : : : {
: : : : : : : static int[] q=new int[80000];
: : : : : : : static int[] a=new int[80000];
: : : : : : : static int[] x=new int[80000];
: : : : : : : static int[] y=new int[80000];
: : : : : : : static int[] dp=new int[80000];
: : : : : : : static int[] d2=new int[80000];
: : : : : : : static int[] d3=new int[80000];
: : : : : : : static int[] d4=new int[80000];
: : : : : : : static int[] p=new int[80000];
: : : : : : : int index=0;
: : : : : : :
: : : : : : : public void windowActivated(WindowEvent ev){}
: : : : : : : public void windowClosed(WindowEvent ev){}
: : : : : : : public void windowClosing(WindowEvent ev){
: : : : : : : //here is 1 exit
: : : : : : : System.exit(0);
: : : : : : : }
: : : : : : : public void windowDeactivated(WindowEvent ev){}
: : : : : : : public void windowDeiconified(WindowEvent ev){}
: : : : : : : public void windowIconified(WindowEvent ev){}
: : : : : : : public void windowOpened(WindowEvent ev){}
: : : : : : :
: : : : : : :
: : : : : : : public void readData() throws IOException
: : : : : : : {
: : : : : : : String currentDirectoryPath = new String();
: : : : : : : currentDirectoryPath = "C://Java//jwintab01//result//";
: : : : : : : JFileChooser fileChooser = new JFileChooser( currentDirectoryPath);
: : : : : : :
: : : : : : : fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
: : : : : : : int result = fileChooser.showOpenDialog(null);
: : : : : : : if(result == JFileChooser.CANCEL_OPTION)
: : : : : : : System.exit(0);
: : : : : : : //here is the 2nd exit.
: : : : : : : File fileName = fileChooser.getSelectedFile();
: : : : : : :
: : : : : : :
: : : : : : : FileInputStream fileInputStream = new FileInputStream(fileName);
: : : : : : : InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
: : : : : : : BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
: : : : : : :
: : : : : : : // reading the 1st row of text file
: : : : : : : String sentence = bufferedReader.readLine();
: : : : : : :
: : : : : : : // setting the minimum and maximum values to 1st row of text file
: : : : : : : StringTokenizer tokenizer = new StringTokenizer(sentence, " ");
: : : : : : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : : // reading 2nd row of text file
: : : : : : : sentence = bufferedReader.readLine();
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : : index=index+1;
: : : : : : :
: : : : : : :
: : : : : : : // check to make sure current row is not the end of file
: : : : : : : while (sentence != null) {
: : : : : : : tokenizer = new StringTokenizer(sentence, " ");
: : : : : : :
: : : : : : : // check to make sure that current row is not empty
: : : : : : : if (tokenizer.hasMoreTokens()) {
: : : : : : : // read in values from current row and set them as max or min values if necessary
: : : : : : : q[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : : a[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : : x[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : : y[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : : dp[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : : d2[index] = Integer.parseInt(tokenizer.nextToken());
: : : : : : : d3[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : : d4[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : : p[index]=Integer.parseInt(tokenizer.nextToken());
: : : : : : :
: : : : : : : index=index+1;
: : : : : : :
: : : : : : : }
: : : : : : :
: : : : : : :
: : : : : : : // read next row of text file; returns null if end of file reached
: : : : : : : sentence = bufferedReader.readLine();
: : : : : : : }
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : : }
: : : : : : :
: : : : : : :
: : : : : : : public void paint(Graphics g)
: : : : : : : {
: : : : : : : setBackground(Color.black);
: : : : : : :
: : : : : : : //draw line of zones
: : : : : : : setForeground(Color.white);
: : : : : : :
: : : : : : : //big spiral
: : : : : : : double e=1;
: : : : : : : for(double q=180;q<700;q++)
: : : : : : : {
: : : : : : : double xaxis, yaxis;
: : : : : : : int xax, yax;
: : : : : : :
: : : : : : : xaxis = e * Math.cos(q/100*Math.PI)+270;
: : : : : : : yaxis = e * Math.sin(q/100*Math.PI)+505;
: : : : : : : e=e-0.5;
: : : : : : : xax= (int)(xaxis);
: : : : : : : yax= (int)(yaxis);
: : : : : : : if(yax<325)
: : : : : : : {
: : : : : : : g.drawOval(xax,(425-(yax-325)),2,2);
: : : : : : : }
: : : : : : : else
: : : : : : : {
: : : : : : : g.drawOval(xax,(425+(325-(yax))),2,2);
: : : : : : : }
: : : : : : : }
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : : for(int i=0; i<1000; i++)
: : : : : : : {
: : : : : : : g.setColor( Color.yellow);
: : : : : : : if((x[i]!=0)&&(y[i]!=0))
: : : : : : : {
: : : : : : :
: : : : : : : g.drawOval(x[i],y[i],5,5);
: : : : : : : }
: : : : : : : }
: : : : : : : }
: : : : : : :
: : : : : : : public FinalResult() throws IOException
: : : : : : : {
: : : : : : :
: : : : : : :
: : : : : : : addWindowListener(this);
: : : : : : : setSize(600,580);
: : : : : : : setVisible(true);
: : : : : : : }
: : : : : : :
: : : : : : : public static void main(String args[]) throws IOException
: : : : : : : {
: : : : : : :
: : : : : : :
: : : : : : : FinalResult g=new FinalResult();
: : : : : : : g.readData();
: : : : : : : g.repaint();
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : : }
: : : : : : : }
: : : : : : :
: : : : : : :
: : : : : : : i wonder if i can use close(), but inside close() i have to put System.exit also?
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : You need to link the WindowListener implementation to the frame using addWindowListener(). See this site for more info: http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
: : : : : :
: : : : :
: : : : :
: : : : : i still dont understand.
: : : : : is it that i have to create a frame and add
: : : : : public void windowClosing(WindowEvent e) {
: : : : : ActionListener task = new ActionListener() {
: : : : : boolean alreadyDisposed = false;
: : : : : public void actionPerformed(ActionEvent e) {
: : : : : if (!alreadyDisposed) {
: : : : : alreadyDisposed = true;
: : : : : frame.dispose();
: : : : : } else {
: : : : : System.exit(0);
: : : : : }
: : : : : }
: : : : : };
: : : : : }
: : : : :
: : : : : but after adding it, i didnt get any error when i compile but when i try to run it, it says there is a NullPointerException.
: : : : :
: : : : :
: : : : Give the following code:
: : : : [code]
: : : : class Closer1 implements WindListener
: : : : {
: : : : public void windowClosing(WindowEvent ev) {
: : : : System.exit(0);
: : : : }
: : : : }
: : : :
: : : : class Closer2 implements WindListener
: : : : {
: : : : public void windowClosing(WindowEvent ev) {
: : : : SaveDataToFile();
: : : : }
: : : : }
: : : :
: : : : class Closer3 implements WindListener
: : : : {
: : : : public void windowClosing(WindowEvent ev) {
: : : : System.exit(1);
: : : : }
: : : : }
: : : :
: : : : class MyFrame extends JFrame
: : : : {
: : : : public MyFrame
: : : : {
: : : : }
: : : : }
: : : : [/code]
: : : : Which Closer object is used as WindowListener implementation?
: : : :
: : : actually system.exit(0) or (1) make no diff right?
: : : so you saying i have to create another class for the exit?
: : :
: : :
: : None are run, because the window doesn't know which to run. The following addition to the frame code specifies which Closer is run:
: : [code]
: : class MyFrame extends JFrame
: : {
: : public MyFrame
: : {
: : this.addWindowListener(new Closer1());
: : }
: : }
: : [/code]
: : Now the frame will run the windowClosing() method in the Closer1 class. This crucial line (addWindowListener) is missing in your code.
: : As for the difference between Exit(0) and Exit(1), there is a difference to the process, which executes the application. It indicates the DOS ERRORLEVEL.
: :
:
:
: class Closer1 implements WindListener
: {
: public void windowClosing(WindowEvent ev) {
: System.exit(0);
: }
: }
: class MyFrame extends JFrame
: {
: public MyFrame
: {
: this.addWindowListener(new Closer1());
: }
: }
:
: if i were type it this way it will have an error of saying is the Closer1 an abstract or class or interface.
:
:
:
:
I've left out the other methods defined in the WindowListener interface for brevity and readability. If you want to run that code, you'll need to add them.
In Java an interface is a promise the programmer makes to the class to implement various methods. So by including the words [b]implements WindowListener[/b] you as a programmer promise to the Java language that that class will implement all the methods in the WindowListener interface.