Just got done rewriting my Gui (probably why it’s not working…).
Added everything the way it previously was, of course removing/fixing (hopefully) all the errors with the Gui.
Trying to add it to my JMenuBar/JMenu/JMenuItem.
Note: Not all 3, but you get an idea where it’s trying to be implemented…
Hoping someone can take the time to read my 2 code snippets… atleast point me in a direction on why my ActionListener isn’t working, and yes my Gui class does implement a ActionListener.
Here’s my actionPerformed method, nothing edited:
public void actionPerformed(ActionEvent evt) {
String cmd = evt.getActionCommand();
try {
if (cmd != null) {
if (cmd.equalsIgnoreCase("Exit")) {
int i;
if ( (i = JOptionPane.showConfirmDialog(this, "Do you really wish to exit the client?")) == 0) {
System.exit(0);
}
System.out.println("does this shit even work...");
}
if (cmd.equalsIgnoreCase("Low Memory")) {
if (!super.lowMem) {
// setlow
super.setLowMem();
} else if (super.lowMem) {
// refuse already low
}
}
if (cmd.equalsIgnoreCase("High Memory")) {
if (super.lowMem) {
// sethigh
super.setHighMem();
} else if (!lowMem) {
// refuse already high
}
}
}
} catch (Exception e) { }
}
Might be kinda long for someone to read, here’s the initUI method (sets up Gui) :
private final void initUI(String title) {
try {
frame = new JFrame(title);
cp = frame.getContentPane();
dim = new Dimension(ClientSettings.w, ClientSettings.h);
initLookAndFeel();
gamePanel = new JPanel();
gamePanel.setLayout(new BorderLayout());
gamePanel.add(this, BorderLayout.CENTER);
gamePanel.setPreferredSize(dim);
frame.setResizable(true);
frame.setDefaultCloseOperation(3);
frame.setLayout(new BorderLayout());
// Begin operations and component setup here..
//begin
frame.setIconImage(JFICON.getImage());
this.menuBar = new JMenuBar();
this.jmenubar = new JMenuBar();
this.fileMenu = new JMenu("File");
this.detailMenu = new JMenu("Memory Settings");
for (String itemOneName : this.fileMenuItems) {
JMenuItem menuItem1 = new JMenuItem(itemOneName);
if (itemOneName.equalsIgnoreCase("-")) {
fileMenu.addSeparator();
} else {
menuItem1.addActionListener(this);
fileMenu.add(itemOneName);
}
}
for (String itemTwoName : this.detailMenuItems) {
JMenuItem menuItem2 = new JMenuItem(itemTwoName);
if (itemTwoName.equalsIgnoreCase("-")) {
detailMenu.addSeparator();
} else {
menuItem2.addActionListener(this);
detailMenu.add(itemTwoName);
}
}
frame.add(jmenubar);
menuBar.add(fileMenu);
menuBar.add(detailMenu);
//end
cp.add(this.menuBar, BorderLayout.NORTH);
cp.add(this.gamePanel, BorderLayout.CENTER);
gamePanel.setBackground(Color.black.darker());
this.setCursor(0); // Regular Gold Cursor
frame.pack(); // Final Frame Init
frame.validate();
frame.setVisible(true);
frame.setLocationRelativeTo(null);
super.init();
} catch (Exception exc) {
exc.printStackTrace(System.err);
System.err.println("A Fatal Exception has occured during runtime!");
System.exit(0);
}
}