What I want to do is have a main JFrame with my application and in addition, if you press certain buttons the jframe will open up a jdialogbox that contains a jeditor pane that displays a website (eventually going to change that to open a html file from local c drive). This is going to be like a help info for user.
I need to know the best way to do this. Once the jdialog is open, when the next button is pressed to open jdialog, I want it to open it in same Jdialog and not an additional one.
The code works ok. but when i click on button one, then on button two to get the second url open. If i move around the jdialog window, then the dialog switches to the first url again. Why?????
Help Please, I'm stuck on this for a while now
I need to know the best way to do this. Once the jdialog is open, when the next button is pressed to open jdialog, I want it to open it in same Jdialog and not an additional one.
The code works ok. but when i click on button one, then on button two to get the second url open. If i move around the jdialog window, then the dialog switches to the first url again. Why?????
Help Please, I'm stuck on this for a while now
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class Test extends JPanel {
public Test(){
testing();
}
public void testing() {
JPanel panel = new JPanel();
panel.add(new JLabel("Hello"));
JButton button = new JButton("Hello");
JButton button2 = new JButton("Button2");
final JDialog dialog = new JDialog();
dialog.setVisible(false);
dialog.setSize(800,800);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
JEditorPane pane = new JEditorPane();
//pane.setVisible(true);
dialog.setVisible(true);
pane.setEditable(false);
URL url = null;
try {
url = new URL("http://fay.iniminimo.com/paint7.html");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
pane.setPage(url);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
dialog.add(pane);
}
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
JEditorPane pane = new JEditorPane();
//pane.setVisible(true);
dialog.setVisible(true);
pane.setEditable(false);
URL url = null;
try {
url = new URL("http://www.google.ca");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
pane.setPage(url);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
dialog.add(pane);
}
});
panel.add(button);
panel.add(button2);
this.add(panel);
}
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setSize(400,400);
Test test = new Test();
frame.add(test);
}
}