I need some help guys, what is broken in my code. I'm new to programming so please be easy on the rude comments thanks.
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
class GUIExampleListener implements WindowListener {
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {
System.exit(0);
}
public void windowClosing(WindowEvent e) {}
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
}
class GUIButton extends JButton {
GUIButton() {
super();
setButtonAttributes();
}
GUIButton(String buttonLabel) {
super(buttonLabel);
setButtonAttributes();
}
private final void setButtonAttributes() {}
}
class GUICloseButton extends GUIButton implements ActionListener {
GUICloseButton() {
super("close this window");
setAttributes();
}
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
private final void setAttributes() {
setBackground(Color.GREEN);
addActionListener(this);
}
}
class GUIExample extends JFrame {
public static final int DEFAULT_HEIGHT = 100;
public static final String DEFAULT_TITLE = "An Example GUI";
public static final int DEFAULT_WIDTH = 100;
private Dimension frameSize = null;
private String title = DEFAULT_TITLE;
GUIExample() throws InstantiationException {
if ( setFrameSize(getHeight(), getWidth()) ) {
add(new GUICloseButton());
addWindowListener(new GUIExampleListener());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}else
throw new InstantiationException("GUIExample cannot be instantiated");
}
final Dimension getFrameSize() {
return frameSize;
}
final boolean setFrameSize(Dimension frameSize) {
boolean success = false;
int height = 0;
int width = 0;
if ( frameSize != null ) {
height = (int)frameSize.getHeight();
width = (int)frameSize.getWidth();
success = setFrameSize(height, width);
}
return returnThis;
}
final boolean setFrameSize(int height, int width) {
boolean success = true;
if( (height > 0) && (width > 0) ) {
try{
this.frameSize = new Dimension(width, height);
setSize(getFrameSize());
}catch (Exception e) {
success = false;
}
}else
success = false;
return success;
}
}
public class GUI {
public static void main(String[]args) {
GUIExample exampleGui = null;
try{
exampleGui = new GUIExample();
}catch (Exception e) {
JOptionPane.showMessageDialog(null, "An unexpected error has occurred");
}
}
}