Start builing Gui, demo creates 2 because the first one doesnt load
This commit is contained in:
parent
a86661a37a
commit
8c5e3a705a
BIN
Medien/Bilder/HackerUnicorn.png
Normal file
BIN
Medien/Bilder/HackerUnicorn.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.0 MiB |
BIN
Medien/Bilder/HackerUnicorn_Schäbig.png
Normal file
BIN
Medien/Bilder/HackerUnicorn_Schäbig.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 210 KiB |
10
src/part5/Demo.java
Normal file
10
src/part5/Demo.java
Normal file
@ -0,0 +1,10 @@
|
||||
package part5;
|
||||
|
||||
public class Demo {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Window w = new Window("My Java GUI");
|
||||
w.display();
|
||||
}
|
||||
}
|
||||
}
|
88
src/part5/Window.java
Normal file
88
src/part5/Window.java
Normal file
@ -0,0 +1,88 @@
|
||||
package part5;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
|
||||
public class Window {
|
||||
private String title;
|
||||
|
||||
public Window(String title){
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public JFrame setup(int height, int width){
|
||||
JFrame w = new JFrame();
|
||||
w.setVisible(true);
|
||||
w.setSize(width,height);
|
||||
w.setTitle(this.title);
|
||||
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
return w;
|
||||
}
|
||||
|
||||
public void display() {
|
||||
JFrame w = setup(700,700);
|
||||
|
||||
JPanel contentPane = new JPanel();
|
||||
|
||||
JButton textFeld = new JButton("Ich bin eine Beschriftung und lebe in einem Button");
|
||||
contentPane.add(textFeld);
|
||||
|
||||
JTextField text = new JFormattedTextField("Hello, I am a formatted Text field \nThis Linebreak may work");
|
||||
contentPane.add(text);
|
||||
|
||||
JLabel vorname = new JLabel("Vorname");
|
||||
JLabel nachname = new JLabel("Nachname");
|
||||
JLabel MatrikelNr = new JLabel("MatrikelNR.");
|
||||
JLabel password = new JLabel("Passwort");
|
||||
JLabel longText = new JLabel("Langer Text");
|
||||
|
||||
JTextField feldVorName = new JTextField(10);
|
||||
JTextField feldNachName = new JTextField(10);
|
||||
JPasswordField feldPassw = new JPasswordField(10);
|
||||
JTextArea feldLongText = new JTextArea(20,15);
|
||||
|
||||
contentPane.add(vorname);
|
||||
contentPane.add(feldVorName);
|
||||
contentPane.add(nachname);
|
||||
contentPane.add(feldNachName);
|
||||
contentPane.add(password);
|
||||
contentPane.add(feldPassw);
|
||||
|
||||
Icon i = new ImageIcon("Medien/Bilder/HackerUnicorn_Schäbig.png");
|
||||
JButton grafik = new JButton(i);
|
||||
contentPane.add(grafik);
|
||||
|
||||
contentPane.add((MatrikelNr));
|
||||
contentPane.add(longText);
|
||||
contentPane.add(feldLongText);
|
||||
|
||||
|
||||
w.setContentPane(contentPane);
|
||||
|
||||
|
||||
JMenuBar menuebar = new JMenuBar();
|
||||
JMenu file = new JMenu("file");
|
||||
JMenu help = new JMenu("help");
|
||||
|
||||
menuebar.add(file);
|
||||
menuebar.add(help);
|
||||
|
||||
JMenuItem fileOpen = new JMenuItem("open");
|
||||
JMenuItem fileClose = new JMenuItem("close");
|
||||
JMenuItem fileEdit = new JMenuItem("edit");
|
||||
JMenuItem helpInfo = new JMenuItem("info");
|
||||
JMenuItem helpUnsub = new JMenuItem("unsubscribe");
|
||||
|
||||
file.add(fileOpen);
|
||||
file.add(fileEdit);
|
||||
file.add(fileClose);
|
||||
help.add(helpInfo);
|
||||
help.add(helpUnsub);
|
||||
|
||||
w.setJMenuBar(menuebar);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user