awt_wttest.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 995 行 · 第 1/3 页

JAVA
995
字号
        alist.setLocation(10, 10);
        alist.setSize(150, 150);
        redpanel.add(alist);

        for (int i = 0; i <= 20; i++) {
            alist.add(i + "  ABCD");
        }
        /*
         * alist.add("1 ABC"); alist.add("2 DEF"); alist.add("3 GHIJKLI");
         * alist.add("4 X12345"); alist.add("5 AdBC"); alist.add("6 DEdF");
         * alist.add("7 GHIbJKLI");
         */

        final JNComboBox combo = new JNComboBox();
        combo.setSize(200, 100);
        combo.setLocation(180, 150);

        for (int i = 0; i < 20; i++) {
            combo.add("ABCD" + i);
        }

        redpanel.add(combo);

        final JNMenu amenu = new JNMenu("");
        amenu.add("abc");
        amenu.add("def");
        amenu.add("ghijklmnop aldkf alkdki");
        amenu.add("jkl");

        amenu.setLocation(10, 180);
        amenu.setSize(amenu.getPreferredSize());
        redpanel.add(amenu);

        window2.add(redpanel);

        return window2;
    }

    public static void main(String[] args) {

        if (true) {
            testWidgets_and_Layouts(false);
            //			testWidgets();
            return;
        }

    }

    public void paint(Graphics g) {
        mgr.repaint();
    }

    protected void processEvent(AWTEvent evt) {
        if (mgr.getCurrentDesktop() != null) {
            // redirect the MouseEvents to the JNode Desktop
            if (evt.getID() >= JNodeMouseEvent.MOUSE_FIRST
                    && evt.getID() <= JNodeMouseEvent.MOUSE_LAST) {
                final MouseEvent mevt = (MouseEvent) evt;
                //				mgr.postEvent(new JNodeMouseEvent(mgr.getCurrentDesktop(),
                // evt.getID(), mevt.getX(), mevt.getY(), mevt.getButton()));
                mgr.postEvent(new JNodeMouseEvent(mgr.getCurrentDesktop(), evt
                        .getID(), mevt.getX(), mevt.getY(), 2));
            } else if (evt.getID() >= JNodeKeyEvent.KEY_FIRST
                    && evt.getID() <= JNodeKeyEvent.KEY_LAST) {
                final KeyEvent kevt = (KeyEvent) evt;
                //				mgr.postEvent(new JNodeMouseEvent(mgr.getCurrentDesktop(),
                // evt.getID(), mevt.getX(), mevt.getY(), mevt.getButton()));
                mgr.postEvent(new JNodeKeyEvent(mgr.getCurrentDesktop(), kevt
                        .getID(), kevt.getKeyCode()));
                //            System.out.println("AWT_WTTEst "+kevt.getKeyChar());
            } else {
                super.processEvent(evt);
            }
        }
    }

    private void startDesktopManager(Dimension screenSize) {
        mgr.setScreenSize(screenSize);
        //		System.out.println("ScreenSize=" + screenSize);
        JNDesktop desktop = mgr.addDesktop();
        desktop.repaint();
    }

    public static void testWidgetLayout() {
        Frame frame = new Frame();
        frame.setSize(800, 600);
        AWT_WTTest panel = new AWT_WTTest();
        panel.setCursor(null);
        frame.add(panel);
        frame.addWindowListener(new WindowListener() {

            public void windowOpened(WindowEvent e) {
            }

            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }

            public void windowClosed(WindowEvent e) {
                System.exit(0);
            }

            public void windowIconified(WindowEvent e) {
            }

            public void windowDeiconified(WindowEvent e) {
            }

            public void windowActivated(WindowEvent e) {
            }

            public void windowDeactivated(WindowEvent e) {
            }
        });
        frame.setLocation(100, 100);
        frame.setBackground(Color.white);
        frame.setVisible(true);
        panel.startDesktopManager(frame.getSize());
        ImageIcon emptyIcon = new javax.swing.ImageIcon("");

        Cursor invisibleCursor = Toolkit.getDefaultToolkit()
                .createCustomCursor(emptyIcon.getImage(), new Point(0, 0),
                        "Invisible Cursor");
        frame.setCursor(invisibleCursor);

        JNWindow window1 = null;

        window1 = new JNWindow();
        window1.setSize(new Dimension(100, 100));
        window1.setLocation(20, 20);
        window1.setVisible(true);

        //JNWindow window2 = getBorderLayoutWindow();

        //JNWindow window3 = getFlowLayoutWindow();
    }

    public static void testWidgets() {
        Frame frame = new Frame();
        frame.setSize(800, 600);
        AWT_WTTest panel = new AWT_WTTest();
        panel.setCursor(null);
        frame.add(panel);
        frame.addWindowListener(new WindowListener() {

            public void windowOpened(WindowEvent e) {
            }

            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }

            public void windowClosed(WindowEvent e) {
                System.exit(0);
            }

            public void windowIconified(WindowEvent e) {
            }

            public void windowDeiconified(WindowEvent e) {
            }

            public void windowActivated(WindowEvent e) {
            }

            public void windowDeactivated(WindowEvent e) {
            }
        });
        frame.setLocation(100, 100);
        frame.setBackground(Color.white);
        frame.setVisible(true);
        panel.startDesktopManager(frame.getSize());
        //ImageIcon emptyIcon = new javax.swing.ImageIcon("");

        //		Cursor invisibleCursor =
        // Toolkit.getDefaultToolkit().createCustomCursor(emptyIcon.getImage(),
        // new Point(0, 0), "Invisible Cursor");
        //		frame.setCursor(invisibleCursor);

        JNWindow window1 = null;

        window1 = new JNWindow();
        window1.setSize(new Dimension(100, 100));
        window1.setLocation(20, 20);
        window1.setVisible(true);

        JNWindow window2 = null;

        window2 = new JNWindow();
        window2.setSize(new Dimension(500, 500));
        window2.setBackground(new Color(207, 207, 207));
        window2.setLocation(150, 30);
        window2.setVisible(true);

        JNPanel redpanel = new JNPanel();
        redpanel.setLocation(0, 50);
        redpanel.setBackground(window2.getBackground());

        addLabelsToPanel(redpanel);
        addCheckBoxsToPanel(redpanel);
        addRadioButtonsToPanel(redpanel);

        JNButton b1 = new JNButton("Button");
        b1.setLocation(100, 300);
        b1.setSize(200, 30);
        redpanel.add(b1);

        window2.add(redpanel);
    }

    public static void testWidgets_and_Layouts(boolean isApplet) {
        final boolean b = isApplet;
        final Frame frame = new Frame();
        frame.setSize(600, 700);
        AWT_WTTest panel = new AWT_WTTest();
        frame.add(panel);
        frame.addWindowListener(new WindowListener() {

            public void windowOpened(WindowEvent e) {
            }

            public void windowClosing(WindowEvent e) {
                if (b) {
                    frame.setVisible(false);
                } else {
                    System.exit(0);
                }
            }

            public void windowClosed(WindowEvent e) {
                if (b) {
                    frame.setVisible(false);
                } else {
                    System.exit(0);
                }
            }

            public void windowIconified(WindowEvent e) {
            }

            public void windowDeiconified(WindowEvent e) {
            }

            public void windowActivated(WindowEvent e) {
            }

            public void windowDeactivated(WindowEvent e) {
            }
        });
        frame.setLocation(100, 0);
        frame.setBackground(Color.white);
        frame.setVisible(true);
        panel.startDesktopManager(frame.getSize());

        //	JNWindow window2 = getBorderLayoutWindow();

        // JNWindow window3 = getFlowLayoutWindow();
        // JNWindow window3 = getFlowLayoutWindow2();
        // JNWindow window3 = getFlowLayoutWindow3();
        //JNWindow window4 = getWidgetsWindow2();

        //JNWindow window4 = getMenu();
        //JNWindow window4 = getMenu2();
        //JNWindow window4 = getPanelLayoutCheck();
        //JNWindow window4 = getTabbedPane();
        //JNWindow window4 = getDemo(isApplet);

        //JNWindow window4 = panelBug();
    }

    public static void testWidgets_and_Layouts_old() {
        Frame frame = new Frame();
        frame.setSize(800, 600);
        AWT_WTTest panel = new AWT_WTTest();
        //panel.setCursor(null);
        frame.add(panel);
        frame.addWindowListener(new WindowListener() {

            public void windowOpened(WindowEvent e) {
            }

            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }

            public void windowClosed(WindowEvent e) {
                System.exit(0);
            }

            public void windowIconified(WindowEvent e) {
            }

            public void windowDeiconified(WindowEvent e) {
            }

            public void windowActivated(WindowEvent e) {
            }

            public void windowDeactivated(WindowEvent e) {
            }
        });
        frame.setLocation(100, 0);
        frame.setBackground(Color.white);
        frame.setVisible(true);
        panel.startDesktopManager(frame.getSize());

        //		ImageIcon emptyIcon = new javax.swing.ImageIcon("");
        //		Cursor invisibleCursor =
        // Toolkit.getDefaultToolkit().createCustomCursor(emptyIcon.getImage(),
        // new Point(0, 0), "Invisible Cursor");
        //		frame.setCursor(invisibleCursor);

        /*
         * JNWindow window1 = null;
         * 
         * window1 = new JNWindow(); window1.setSize(new Dimension(100,100));
         * window1.setLocation(20,20);
         */

        //	JNWindow window2 = getBorderLayoutWindow();
        //JNWindow window3 = getFlowLayoutWindow();
        // JNWindow window3 = getFlowLayoutWindow2();
        //JNWindow window4 = getWidgetsWindow2();
        //JNWindow window4 = getMenu();
        //JNWindow window4 = getMenu2();
        //JNWindow window4 = getPanelLayoutCheck();
        //JNWindow window4 = getTabbedPane();
        //JNWindow window4 = panelBug();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?