Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Jason Perry   on Feb 11 In Java Category.

  
Question Answered By: Ana Silva   on Feb 11

1. Use singleton design pattern(have a look to
http://www.patterndepot.com/put/8/Singleton.PDF) for creating if you want to
create only one instance of a class.
If it is not easy to understand you can do sometihng like that
Use a handle in the class which listens the action of your button but it should
be static (such as static boolean isWindowCreated)
Set this flag when you create a window to true.And control the state of this
flag before handling the event of your button.An example  code is in below:
public class JFrmMainWindow extends JFrame implements

static boolean isWindowCreated=false;
java.awt.event.ActionListener{
JButton newWindow = new JButton();
public JFrmMainWindow() {
init();
}
public static void main(String[] args) {
JFrmMainWindow jFrmMainWindow = new JFrmMainWindow();

}
private void init() {
newWindow.setBounds(new Rectangle(134, 211, 132, 45));
newWindow.setText("New Window");
newWindow.addActionListener(this);
this.setSize(500,400);
this.getContentPane().setLayout(null);
this.getContentPane().add(newWindow, null);
this.setVisible(true);
}

private void createNewWindowAndShowIt(){
if(!isWindowCreated){
JFrame newWindow=new JFrame();
newWindow.setSize(100,100);
newWindow.setVisible(true);
isWindowCreated=true;
}
}
public void actionPerformed(ActionEvent e) {
createNewWindowAndShowIt();
}
}

2. Null pointer exception means you did not create an instance but you are
trying to use it.
E.g
SimpleClass anInstanceOfSimpleClass;
anInstanceOfSimpleClass.makeASimpleThing();

3.You can navigate a folder with javax.swing.JFileChooser
Maybe you can navigate a web page with Runtime.getRuntime().exec method you can
execute iexplore but you can't naigate a web a page with swing  directly.maybe
there can be some libs maybe you can look to www.sf.net

Your questions are not clear maybe you can put some example codes to your mails

Share: