Results 1 to 3 of 3

Thread: JFrame

  1. #1
    aldo is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default JFrame

    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

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Have a look here to get started
    Trail: Creating a GUI with JFC/Swing
    and here for more
    How to Use Icons.

  3. #3
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    It is logic )))

    Try to insert an iterator in you actionPerformed method
    i++;
    if(i>1)return;

    That should work )))
    Last edited by Webuser; 06-24-2009 at 06:11 AM.

Similar Threads

  1. how to use JFrame in JSP ??
    By priyanka sharma in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 04-06-2011, 05:51 AM
  2. Replies: 4
    Last Post: 04-23-2009, 12:02 AM
  3. Help in JFrame
    By kirtesh4u in forum New To Java
    Replies: 2
    Last Post: 11-18-2008, 01:40 AM
  4. help in JFrame
    By kirtesh4u in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2008, 01:26 AM
  5. jframe
    By amith in forum AWT / Swing
    Replies: 1
    Last Post: 05-15-2008, 11:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •