Start with good (?) Version.
Just adding MenuBar does not show?
This commit is contained in:
parent
8c5e3a705a
commit
238759ad89
@ -2,9 +2,13 @@ package part5;
|
|||||||
|
|
||||||
public class Demo {
|
public class Demo {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
for (int i = 0; i < 2; i++) {
|
// for (int i = 0; i < 2; i++) {
|
||||||
Window w = new Window("My Java GUI");
|
// Window w = new Window("My Java GUI");
|
||||||
w.display();
|
// w.display();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
aufg gudWindow = new aufg("Title", 300, 420);
|
||||||
|
gudWindow.display(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
64
src/part5/aufg.java
Normal file
64
src/part5/aufg.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package part5;
|
||||||
|
|
||||||
|
import javax.management.remote.JMXAddressable;
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.random.RandomGenerator;
|
||||||
|
|
||||||
|
public class aufg {
|
||||||
|
private String title;
|
||||||
|
private int height;
|
||||||
|
private int width;
|
||||||
|
private JFrame window;
|
||||||
|
private JPanel contentPane;
|
||||||
|
private JMenuBar menubar;
|
||||||
|
|
||||||
|
public aufg(String title, int height, int width){
|
||||||
|
this.title = title;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.window = new JFrame();
|
||||||
|
this.contentPane = new JPanel();
|
||||||
|
this.menubar = new JMenuBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void display(boolean exitOnClose){
|
||||||
|
this.window.setTitle(this.title);
|
||||||
|
this.window.setSize(this.width, this.height);
|
||||||
|
this.window.setVisible(true);
|
||||||
|
|
||||||
|
if (exitOnClose){
|
||||||
|
this.window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMenuBar(){
|
||||||
|
JMenu file = new JMenu("File");
|
||||||
|
JMenuItem fileOpen = new JMenuItem("Open");
|
||||||
|
JMenuItem fileEdit = new JMenuItem("Edit");
|
||||||
|
JMenuItem fileClose = new JMenuItem("Close");
|
||||||
|
file.add(fileOpen);
|
||||||
|
file.add(fileEdit);
|
||||||
|
file.add(fileClose);
|
||||||
|
|
||||||
|
JMenu help = new JMenu("Help");
|
||||||
|
JMenuItem helpInfo = new JMenuItem("Info");
|
||||||
|
JMenuItem helpUnsub = new JMenuItem("Unsubscribe");
|
||||||
|
help.add(helpInfo);
|
||||||
|
help.add(helpUnsub);
|
||||||
|
|
||||||
|
JMenu english = new JMenu("English");
|
||||||
|
JMenuItem englishChangeTo = new JMenuItem("Change to English");
|
||||||
|
english.add(englishChangeTo);
|
||||||
|
|
||||||
|
JMenu braile = new JMenu("Braile");
|
||||||
|
JMenuItem braileChangeTo = new JMenuItem("Change to Braile");
|
||||||
|
braile.add(braileChangeTo);
|
||||||
|
|
||||||
|
this.menubar.add(file);
|
||||||
|
this.menubar.add(help);
|
||||||
|
this.menubar.add(english);
|
||||||
|
this.menubar.add(braile);
|
||||||
|
|
||||||
|
this.window.setJMenuBar(this.menubar);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user