Hi everybody.
I created a JFrame and i added an Icone on it.I created a pannel with 2 bottons on it that one of them has to make the JFrame visible ( and till here everything is ok) and the other on click has to kill that frame.The first button works but not as it should. anytime i click on it ti creates me a new frame . (i want that to create only one frame even u click 100 times).The second button on click doesent kill the frames created before.(how can i make it kill the frames created before??????)
here's the code
public class TestIconeImage {
public static void main(String [] arg){
IconeImageRepaint iIRepaint = new IconeImageRepaint();
iIRepaint.nuovoIconeImage();
iIRepaint.creaBottone();
// IconeImage iImage = new IconeImage();
// iImage.visible();
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class IconeImageRepaint {
Button bottoneVis , bottone1;
IconeImage ima;
JTextField textField;
public IconeImage nuovoIconeImage(){
ima = new IconeImage();
return ima;
}
/*IconeImage im;
public void creaInstanza(){
im = new IconeImage();
im.notvisible();
}
public IconeImage fikedriten(){
return im;
}*/
public void creaBottone(){
JFrame frame = new JFrame("the controller");
Container container = frame.getContentPane();
bottoneVis = new Button("visualiza");
bottoneVis.setSize(20,60);
bottoneVis.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//textField.setText("bottone funziona");
ima.visible();
}
}
);
// textField = new JTextField(40);
bottone1 = new Button("nascondi");
bottone1.setSize(20, 60);
bottone1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event1){
ima.notvisible();
}
}
);
container.setLayout(new FlowLayout(FlowLayout.LEFT));
container.add(bottoneVis);
container.add(bottone1);
//container.add(textField);
frame.setSize(300, 100);
frame.setVisible(true);
}
/*
public void defineActions(){
bottoneVis.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
textField.setText("bottone funziona");
// nuovoIconeImage();
// ima.visible();
}
}
);
}
public void defineNewAction(){
bottone1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event1){
ima.notvisible();
}
}
);
} */
}
//} +*
import java.awt.*;
import javax.swing.*;
public class IconeImage {
boolean ok = false;
JFrame frame ;
/*public static void main(String [] arg){
ImageIcon image = new ImageIcon("/home/aldo/workspace/provimi/src/progInternet2008/core/turnOffLight.jpg");
JFrame frame = new JFrame("photo at night");
Container content = frame.getContentPane();
//JLabel label = new JLabel("hej whats up?");
JLabel label = new JLabel(image);
//label.setPreferredSize(new Dimension(300,300));
//label.setSize(200, 300);
content.add(label);
//content.setSize(200, 300);
frame.setSize(500, 900);
frame.setVisible(true);
//frame.setSize(500,500);
}*/
public void paint(){
ImageIcon image = new ImageIcon("/home/aldo/workspace/provimi/src/progInternet2008/core/turnOffLight.jpg");
frame = new JFrame("photo at night");
Container content = frame.getContentPane();
//JLabel label = new JLabel("hej whats up?");
JLabel label = new JLabel(image);
//label.setPreferredSize(new Dimension(300,300));
//label.setSize(200, 300);
content.add(label);
//content.setSize(200, 300);
frame.setSize(500, 900);
frame.setVisible(ok);
frame.repaint();
System.out.println("ok we are here");
//frame.setSize(500,500);
}
public void visible(){
ok = true;
paint();
}
public void notvisible(){
ok = false ;
paint();
frame.disable();
//System.out.println("il frame non è visible");
}
}
//} +*
please helpppp