Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-15-2009, 12:52 PM
Member
 
Join Date: Dec 2008
Posts: 5
Rep Power: 0
aldo is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 06-15-2009, 06:11 PM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
Have a look here to get started
Trail: Creating a GUI with JFC/Swing
and here for more
How to Use Icons.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-24-2009, 06:08 AM
Senior Member
 
Join Date: Dec 2008
Posts: 197
Rep Power: 2
Webuser is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a Jframe un-focusable when another Jframe is active? Robert_85 Advanced Java 4 04-23-2009 12:02 AM
how to use JFrame in JSP ?? priyanka sharma JavaServer Pages (JSP) and JSTL 7 11-28-2008 08:03 AM
Help in JFrame kirtesh4u New To Java 2 11-18-2008 01:40 AM
help in JFrame kirtesh4u AWT / Swing 1 11-18-2008 01:26 AM
jframe amith AWT / Swing 1 05-15-2008 11:03 AM


All times are GMT +2. The time now is 07:29 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org