6
Layout managers
- import java.awt.event.*;
- import java.awt.*;
- public class SimpleFlow {
- public static void main(String[] args) {
- ApplicationWindow appwin = new ApplicationWindow("Application");
- appwin.setVisible(true);
- }
- static class ApplicationWindow extends Frame {
- ApplicationWindow(String name) {
- super(name);
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- Menu filemenu = new Menu("File", true);
- MenuItem quit = new MenuItem("Quit");
- quit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- filemenu.add(quit);
- MenuBar menubar = new MenuBar();
- menubar.add(filemenu);
- setMenuBar(menubar);
- setLayout(new FlowLayout(FlowLayout.CENTER, 50, 20));
- Label l1 = new Label("Do you really want to quit?");
- add(l1);
- Button b1 = new Button("Yes");
- add(b1);
- Button b2 = new Button("No");
- add(b2);
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- int width = 200;
- int height = 150;
- int x = (screenSize.width - width) / 2;
- int y = (screenSize.height - height) / 3;
- setBounds(x, y, width, height);
- setResizable(true);
- }
- }
- }
$ javac SimpleFlow.java
$ java SimpleFlow
Comments