CaptainMimbl
Newbie
- Registriert
- Nov. 2014
- Beiträge
- 2
Hallo Liebe Community, ich bin neu hier und habe begonnen mit Java zu programmieren mein bisheriger Code sieht so aus:
es gibt keine Fehlermeldungen ich wollte einfach wissen was ich machen muss damit ich einen button in dem Fenster worldeditor und optionsf machen kann. Dann wie kann ich machen das wenn ich das Fenster worldeditor öffne das dann das Fenster frame sich schliess und wenn ich dann zurück gehe dass sich das Fenster frame wieder öffnet.
MFG CM
Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class frame extends JFrame implements ActionListener {
private JButton play;
private JButton options;
private JButton close;
public static void main(String[] args){
frame frame = new frame ("GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,400);
frame.setLayout(null);
frame.setVisible(true);
}
public frame (String title){
super(title);
play = new JButton ("Play");
play.setBounds(120, 60, 160, 40);
play.addActionListener(this);
add(play);
options = new JButton ("Options");
options.setBounds(120, 150, 160, 40);
options.addActionListener(this);
add(options);
close = new JButton ("Close");
close.setBounds(120, 240, 160, 40);
close.addActionListener(this);
add(close);
}
public void actionPerformed(ActionEvent e){
if (e.getSource()== play){
worldeditor();
}
if (e.getSource()== options){
optionsf();
}
if (e.getSource()== close){
System.exit(0);
}
}
public static void worldeditor(){
JFrame worldeditor = new JFrame ("World Editor");
worldeditor.setSize(500, 500);
worldeditor.setVisible(true);
}
public static void optionsf() {
JFrame optionsf = new JFrame ("Options");
optionsf.setSize(500, 500);
optionsf.setVisible(true);
}
}
MFG CM