Practiced hand java GUI (g)

2010-12-11  来源:本站原创  分类:Java  人气:96 

A CardLayout example:

package gui.test10;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 *  Cancel the layout manager :
 * container.setLayout(null);
 *  Using absolute positioning :setBounds(....)
 *
 * @author junlas
 *
 */
public class TestCardLayout extends Frame {
        private CardLayout cl = new CardLayout();
        //
        Panel plCenter = new Panel();

        public TestCardLayout() {
                Panel plWest = new Panel();
                plWest.setLayout(new GridLayout(3, 1));
                Button btnPrev = new Button("prev");
                Button btnNext = new Button("next");
                Button btnThree = new Button("three");
                plWest.add(btnPrev);
                plWest.add(btnNext);
                plWest.add(btnThree);
                plCenter.setLayout(cl);
                plCenter.add(new Button("one"),"1");
                plCenter.add(new Button("two"),"2");
                plCenter.add(new Button("three"),"3");
                plCenter.add(new Button("four"),"4");
                plCenter.add(new Button("five"),"5");

                myActionListener ma = new myActionListener();
                btnPrev.addActionListener(ma);
                btnNext.addActionListener(ma);
                btnThree.addActionListener(ma);

                //
                add(plWest,BorderLayout.WEST);
                add(plCenter);

                //
                addWindowListener(new WindowAdapter() {

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

                });
        }

        private class myActionListener implements ActionListener{

                @Override
                public void actionPerformed(ActionEvent e) {
                        if(e.getActionCommand().equals("prev")){
                                cl.previous(plCenter);
                        }else if(e.getActionCommand().equals("next")){
                                cl.next(plCenter);
                        }else{
                                cl.show(plCenter, "3");
                        }
                }

        }

        public static void main(String[] args) {
                TestCardLayout mainFrame = new TestCardLayout();
                mainFrame.setSize(400, 400);
                mainFrame.setTitle("TestCardLayout");
                mainFrame.setVisible(true);
        }
}
相关文章
  • Practiced hand java GUI (g) 2010-12-11

    A CardLayout example: package gui.test10; import java.awt.BorderLayout; import java.awt.Button; import java.awt.CardLayout; import java.awt.Frame; import java.awt.GridLayout; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.e

  • Practiced hand java GUI (b) 2010-12-05

    Using the so-called double-buffering (only heard of) the drawing: package gui.test05; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; import java.awt.Image; import java.awt.even

  • Practiced hand java GUI (c) 2010-12-07

    Custom components (timer): package gui.test06; import java.awt.AWTEvent; import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.text.ParseException; import java.text.SimpleDateFormat; im

  • Practiced hand java GUI (a) 2010-11-28

    java swing has largely forgotten about it, all right time to start practicing hands. Hope that through the wing of a passing shrimp, lots of pointing .. ~ ~ ~ Tse The following is a one to one chat to do a small program: The first step: Design view;

  • Practiced hand java GUI (d) 2010-12-08

    GUI menu: package gui.test07; import java.awt.CheckboxMenuItem; import java.awt.Frame; import java.awt.Menu; import java.awt.MenuBar; import java.awt.MenuItem; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt

  • Practiced hand java GUI (V) 2010-12-10

    Dialog (modal and non-modal two, FileDialog no examples): package gui.test08; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Frame; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListe

  • Practiced hand java GUI (f) 2010-12-11

    Checkbox and radio button example: package gui.test08; import java.awt.Checkbox; import java.awt.CheckboxGroup; import java.awt.Choice; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.event.ItemEvent; import java.awt.event.ItemList

  • Practiced hand java GUI (h) 2010-12-11

    Finally, a small Liezi, that's a little swing compared with the awt: package gui.test11; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; im

  • JAVA GUI 开发---水晶图片按钮 2010-08-27

    JAVA GUI开发中,一个小小的简单的图片按钮,原来如此简单. 说明:1.图片要与按钮设置的大小一样. 2.要水晶效果,要用水晶图片. 源代码如下: import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import j

  • 使用JRuby测试Java GUI 2013-10-17

    与单元测试相比,GUI测试要耗时和困难的多,即使是在测试驱动的开发团队中,因此也常被忽视.让我们来看一看两个为SWT和Swing应用创建GUI测试的解决方案,它们均宣称能够使GUI测试工作更加简单. 为什么GUI测试难以编写?比起简单的实例化一个类,GUI通常需要更多的创建工作,同时因为GUI交互是异步的而且涉及到鼠标操作,所以难以模拟 用户行为.GUI测试的一个方法是提供一个交互录制器,监控测试人员,创建一个以后能够重用的脚本.这种方法存在若干问题:根据录制格式的不同,脚本在 UI改变之后可能

  • 细说Java GUI:AWT,SWT,Swing 2014-02-05

    历史 Internet上有许多围绕这一争论的故事.你可能已经听说过它们中的大多数了,其中之一有助于让你理清头绪,让我们就从这里开始,Amy Fowler是Swing阵营的一个倡导者. 回到上个世纪90年代,曾几何时有3家庞大的Smalltalk公司--IBM.Parc-Place和 Digitalk.在90年代初期3家公司的市场份额大致相等,生活是美好的.Parc-Place采用仿窗口部件(emulated widgets)的设计(即Swing的设计),IBM和Digitalk则采用原生窗口部件

  • JAVA GUI 开发---登录界面加载背景图片 2010-08-23

    package com.ycty.totlosystem.gui.test; import java.awt.Graphics; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import ja

  • [Want to start a full SmartRcp] Flex + Java GUI program development 2010-06-18

    Ready to use before the development of GUI Java Desktop program, online google for a long time, most of SWT and Swing, accidentally discovered the OpenSource of SmartRcp, listening to the author's introduction, like that. Be prepared to learn a simpl

  • JAVA GUI 开发---界面加载背景图片 2010-08-23

    窗口加载一个图片做为背景,简单就是这样简单. import java.awt.Graphics; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class ImgJframeTest { private JFrame jframe; private JButton jbutton; private JPan

  • java GUI 2012-11-14

    一. 概述: GUI图形用户界面 GLI命令行 二. 包 java.Awt:抽象窗口工具包,需要调用本地系统方法实现功能.属重量级控件. javax.Swing:在AWT的基础上,建立的一套图形界面系统,其中提供了更多的组件,而且完全由JAVA实现.增强了移植性,属轻量级控件. 三. 继承关系 Component: Button Label Checkbox TextComponent:TextArea.TextField Container: Window: Frame Dialog:File

  • Java GUI实用小工具集 Common Gui Tools 1.0 使用说明 2013-03-20

    Common Gui Tools 是用java编写,GUI界面的实用小工具集,1.0版暂有6个小工具: 1,编码转换:Character Converter 2,加密解密:Encrypt And Decrypt 3,正则表达式验证:Regex Tester 4,执行Script脚本:Run Script 5,文件(夹)查找操作Folder And File Operate 6,运行环境信息:System Information 欢迎您使用并提供宝贵意见! 配置说明: 1,本软件采用插件方式,6个

  • Java GUI navigation tree tri-state 2010-03-27

    1 through Java Swing implementation of a three-state tree of components, including the choice to choose, semi-state selection for network management and other C / S structure software 2 code is the complete integration of multiple versions / number o

  • JAVA GUI in a text box (JTextField) to monitor changes in the text box 2010-10-29

    As a cross-platform programming solution, Java is clearly not like the Delphi, as the user interface design to provide powerful, intuitive and efficient design support. For example, a text box control, when we perceived in the program if the user cha

  • Practiced hand java thread (IV) 2010-12-19

    Executor thread pool used to build, should do: 1). Call the static method in the Executors class newCachedThreadPool (if necessary, create a new thread, the thread will be kept idle for 60 seconds) or newFixedThreadPool (containing a fixed number of

  • Practiced hand java thread (V) 2010-12-19

    Lock the object through the lock () and unlock () method to simulate the module to be synchronized. 1.Lock lock = new ReentrantLock (); 2.ReadWriterLock rwl = new ReentrantReadWriterLock (); is used to maintain the separation of read and write lock,