hallo, ich würde gerne buttons, die ich erzeugt habe in der Position ändern, wie mach ich das ?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CopyOftextapp2 extends JFrame implements ActionListener {
private JTextField inputField;
private JTextArea outputArea;
private JButton submitButton;
private JButton submitButton2;
public CopyOftextapp2() {
JLabel inputLabel = new JLabel("Bitte geben Sie eine Zahl ein:");
inputField = new JTextField(10);
submitButton = new JButton("Eingabe");
submitButton.addActionListener(this);
submitButton2= new JButton("Beenden");
submitButton2.addActionListener(this);
outputArea = new JTextArea(100, 160);
JScrollPane outputPane = new JScrollPane(outputArea);
Container container = getContentPane();
container.setLayout(new FlowLayout());
container.add(inputLabel);
container.add(inputField);
container.add(submitButton);
container.add(submitButton2);
container.add(outputPane);
setSize( Toolkit.getDefaultToolkit().getScreenSize() );
submitButton13.setBounds( 100, 100, 600, 250 );
setBounds( 20, 20, 70, 100 );
GraphicsDevice device;
device=GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0];
setUndecorated( true );
device.setFullScreenWindow(this);
setTitle("Text App");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] args) {
CopyOftextapp2 app = new CopyOftextapp2();
}
public void actionPerformed(ActionEvent e) {
// Neue Parameter hinzugefügt
if(e.getSource() == this.submitButton){
int inputNumber = Integer.parseInt(inputField.getText());
switch ( inputNumber ) {
case 1:
String text = "Sie haben die Zahl 1 eingegeben.";
outputArea.setText(text);
break;
case 2:
String text2 = "Sie haben die Zahl 2 eingegeben.";
outputArea.setText(text2);
break;
default:
String text3 = "Sie haben die falsche Zahl eingegeben.";
outputArea.setText(text3);
}
}
else if(e.getSource() == this.submitButton2){
int result = JOptionPane.showConfirmDialog(null,"Wollen sie das Programm wirklich beenden", "Programm beenden", JOptionPane.YES_NO_OPTION);
switch(result){
case JOptionPane.YES_OPTION:
System.exit(0);
case JOptionPane.NO_OPTION:
}
}
}
}