Hallo, ich versuche, ein Fenster mit einem TextField zu erstellen. Dieses lässt sich leider nicht positionieren.
Weder mit setLocation noch mit setBounds. Es bewegt sich absolut nicht und bleibt immer an der gleichen Stelle.
[CODE lang="java" highlight="75"]package main;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import dialogs.StoryBeginn;
public class Window extends JFrame implements ActionListener {
public static JFrame frame;
public static final int WIDTH = 700;
public static final int HEIGHT = 700;
public static final String NAME = "Unbekanntes Projekt - 0.1";
public static final JPanel mainpanel = new JPanel();
public static final JPanel upperpanel = new JPanel();
public static final JPanel lowerpanel = new JPanel();
public static JLabel TITLE = new JLabel();
public static JTextArea TEXT = new JTextArea();
public static JTextArea DIALOG = new JTextArea();
public static JTextField EINGABE = new JTextField(20);
public static JButton dialogAuswahlA = new JButton();
public static JButton dialogAuswahlB = new JButton();
public static JButton INVENTORY = new JButton();
public static JButton ERKUNDEN = new JButton();
public static JButton START = new JButton("Start");
public static JButton EXIT = new JButton("Exit");
public static final Font fontNormal = new Font("Arial", 0, 20);
public static final Font fontFett = new Font("Arial", Font.BOLD, 30);
public static final Color backgroundColor = new Color(128,186,195);
public Window() {
setTitle(NAME);
setSize(WIDTH, HEIGHT);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainpanel.setBackground(backgroundColor);
add(mainpanel);
upperpanel.setBackground(Color.gray);
upperpanel.setPreferredSize(new Dimension(50,50));
add(upperpanel, BorderLayout.NORTH);
lowerpanel.setBackground(Color.gray);
lowerpanel.setPreferredSize(new Dimension(50,50));
add(lowerpanel, BorderLayout.SOUTH);
TITLE.setText("Hauptmenü");
TITLE.setFont(fontFett);
upperpanel.add(TITLE);
TEXT.setText("");
TEXT.setEditable(false);
TEXT.setLineWrap(true);
TEXT.setWrapStyleWord(true);
TEXT.setBounds(100, 100, 500, 500);
TEXT.setBackground(backgroundColor);
TEXT.setFont(fontNormal);
mainpanel.add(TEXT);
EINGABE.setLocation(0, 400);
mainpanel.add(EINGABE);
START.addActionListener(this);
EXIT.addActionListener(this);
START.setFont(fontNormal);
EXIT.setFont(fontNormal);
lowerpanel.add(START);
lowerpanel.add(EXIT);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == START) {
StoryBeginn storyBeginn = new StoryBeginn();
storyBeginn.getClass();
}
if (e.getSource() == EXIT) {
System.exit(0);
}
}
}
[/CODE]
Könnt ihr mir helfen?
Weder mit setLocation noch mit setBounds. Es bewegt sich absolut nicht und bleibt immer an der gleichen Stelle.
[CODE lang="java" highlight="75"]package main;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import dialogs.StoryBeginn;
public class Window extends JFrame implements ActionListener {
public static JFrame frame;
public static final int WIDTH = 700;
public static final int HEIGHT = 700;
public static final String NAME = "Unbekanntes Projekt - 0.1";
public static final JPanel mainpanel = new JPanel();
public static final JPanel upperpanel = new JPanel();
public static final JPanel lowerpanel = new JPanel();
public static JLabel TITLE = new JLabel();
public static JTextArea TEXT = new JTextArea();
public static JTextArea DIALOG = new JTextArea();
public static JTextField EINGABE = new JTextField(20);
public static JButton dialogAuswahlA = new JButton();
public static JButton dialogAuswahlB = new JButton();
public static JButton INVENTORY = new JButton();
public static JButton ERKUNDEN = new JButton();
public static JButton START = new JButton("Start");
public static JButton EXIT = new JButton("Exit");
public static final Font fontNormal = new Font("Arial", 0, 20);
public static final Font fontFett = new Font("Arial", Font.BOLD, 30);
public static final Color backgroundColor = new Color(128,186,195);
public Window() {
setTitle(NAME);
setSize(WIDTH, HEIGHT);
setLocationRelativeTo(null);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainpanel.setBackground(backgroundColor);
add(mainpanel);
upperpanel.setBackground(Color.gray);
upperpanel.setPreferredSize(new Dimension(50,50));
add(upperpanel, BorderLayout.NORTH);
lowerpanel.setBackground(Color.gray);
lowerpanel.setPreferredSize(new Dimension(50,50));
add(lowerpanel, BorderLayout.SOUTH);
TITLE.setText("Hauptmenü");
TITLE.setFont(fontFett);
upperpanel.add(TITLE);
TEXT.setText("");
TEXT.setEditable(false);
TEXT.setLineWrap(true);
TEXT.setWrapStyleWord(true);
TEXT.setBounds(100, 100, 500, 500);
TEXT.setBackground(backgroundColor);
TEXT.setFont(fontNormal);
mainpanel.add(TEXT);
EINGABE.setLocation(0, 400);
mainpanel.add(EINGABE);
START.addActionListener(this);
EXIT.addActionListener(this);
START.setFont(fontNormal);
EXIT.setFont(fontNormal);
lowerpanel.add(START);
lowerpanel.add(EXIT);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == START) {
StoryBeginn storyBeginn = new StoryBeginn();
storyBeginn.getClass();
}
if (e.getSource() == EXIT) {
System.exit(0);
}
}
}
[/CODE]
Könnt ihr mir helfen?