package window;
import java.awt.event.*;
import javax.swing.*;
class MenuFrame extends JFrame implements ActionListener {
private static boolean time = true;
private static String host = "domain";
MenuFrame(String name) {
super (name);
JMenuBar mb = new JMenuBar();
JMenuItem mi;
JMenu option = new JMenu("Options");
ButtonGroup bg = new ButtonGroup();
JRadioButtonMenuItem rbmi = new JRadioButtonMenuItem("Show domain");
option.add(rbmi);
bg.add(rbmi);
rbmi.setSelected(true);
rbmi.addActionListener(this);
rbmi = new JRadioButtonMenuItem("Show IP");
option.add(rbmi);
bg.add(rbmi);
rbmi.addActionListener(this);
rbmi = new JRadioButtonMenuItem("Show host");
option.add(rbmi);
bg.add(rbmi);
rbmi.addActionListener(this);
JCheckBoxMenuItem cbmi = new JCheckBoxMenuItem("Show time");
option.add(cbmi);
cbmi.setSelected(true);
cbmi.addActionListener(this);
option.addSeparator();
option.add(mi = new JMenuItem("Close"));
mi.addActionListener(this);
mb.add(option);
JMenu help = new JMenu("Help");
help.add(mi = new JMenuItem("About"));
mi.addActionListener(this);
mb.add(help);
setJMenuBar(mb);
}
static String getMenuHost() {
return host;
}
static boolean getMenuTime() {
return time;
}
public void actionPerformed(ActionEvent e) {
String strAction = e.getActionCommand();
System.out.println(strAction);
if (strAction == "Show time") {
time = !time;
}
if (strAction == "Show domain") {
host = "domain";
}
if (strAction == "Show IP") {
host = "ip";
}
if (strAction == "Show host") {
host = "host";
}
if (strAction == "Close") {
Object[] options = {"Yes", "No"};
int answer = JOptionPane.showOptionDialog(null, "Would you like to close this program?", "Question",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
if (answer == 0) {
System.exit(0);
}
}
if (strAction == "About") {
JOptionPane.showMessageDialog(new JFrame(), "Chat - 2004 by Robert RybiaĆski", "Information", JOptionPane.INFORMATION_MESSAGE);
}
}
}