package com.fxb.gui;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import javax.swing.GroupLayout.Alignment;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.UIManager; public class Test2_JFrame extends JFrame{ JButton button1 = new JButton("Button1");
JButton button2 = new JButton("Button2");
JButton button3 = new JButton("Button3");
TextField field = new TextField(10);
JComboBox comboBox = new JComboBox();
JCheckBox checkBox = new JCheckBox("Check1");
JRadioButton radioButton1 = new JRadioButton("Radio1");
JRadioButton radioButton2 = new JRadioButton("Radio1"); ButtonGroup buttonGroup = new ButtonGroup(); public Test2_JFrame(){
// try{
//// UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName( ) );
//// UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
//// UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel" );
// }catch(Exception e){
// e.printStackTrace();
// } setVisible(true);
setLayout(new FlowLayout(FlowLayout.LEFT ));
// setLayout(new FlowLayout(FlowLayout.CENTER ));
setSize(300, 300);
setAutoRequestFocus(false);
setResizable(false); JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 2, 10, 5));
panel.setSize(200, 200);
add(panel); panel.add(button1);
panel.add(button2);
panel.add(button3);
//panel.add(field); comboBox.addItem("Item1");
comboBox.addItem("Item2");
comboBox.addItem("Item3");
panel.add(comboBox); panel.add(checkBox);
buttonGroup.add(radioButton1);
buttonGroup.add(radioButton2);
panel.add(radioButton1);
panel.add(radioButton2); JTextArea textArea = new JTextArea();
textArea.setSize(100, 100);
add(textArea); // add(button1);
// add(button2);
// add(button3); button1.addActionListener(actionListener);
button2.addActionListener(actionListener);
button3.addActionListener(actionListener);
} private ActionListener actionListener = new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button1){
pt("button1");
}else if(e.getSource() == button2){
pt("button2");
}else if(e.getSource() == button3){
pt("button3");
}
}
}; private static StringBuilder builder = new StringBuilder();
public static void pt(Object a){
builder.setLength(0);
builder.append(a);
System.out.println(builder.toString());
} public static void main(String[] args){
new Test2_JFrame();
} }

JFrame2的更多相关文章

随机推荐

  1. 性能优化1--UI优化

    1.使用系统为我们提供了几个抽象的标签 ①include:重用 include中layout属性指定一个外部布局文件,通过该方式则不需要把这个布局文件在该代码中重复的写一遍了. 若include指定了 ...

  2. spring静态代理和动态代理

    本节要点: Java静态代理 Jdk动态代理 1 面向对象设计思想遇到的问题 在传统OOP编程里以对象为核心,并通过对象之间的协作来形成一个完整的软件功能,由于对象可以继承,因此我们可以把具有相同功能 ...

  3. 自动化测试的Selenium的python版安装与使用

    Selenium是专做网页自动化测试的,即web drive,通过百度Selenium就能找到Selenium的官网 由图可见,selenium支持相当多的编程语言进行网页自动化测试,这里我们使用py ...

  4. jQuery -- 光阴似箭(一):初见 jQuery -- 基本用法,语法,选择器

    jQuery -- 知识点回顾篇(一):初见jQuery -- 基本用法,语法,选择器 1. 使用方法 jQuery 库位于一个 JavaScript 文件中,其中包含了所有的 jQuery 函数. ...

  5. PHP匿名函数

    PHP匿名函数 匿名函数(Anonymous functions),也叫闭包函数(closures),允许临时创建一个没有指定名称的函数.最经常用作回调函数(callback)参数的值. 举例: &l ...

  6. 推荐几本FPGA书籍(更新中)

    1.<数字信号处理的FPGA实现>第三版 讲解比较详细的DSP理论,使用FPGA实现,不过使用VHDL语言:也颇具参考性. 2. <Xilinx Zynq-7000 嵌入式系统设计与 ...

  7. 【Teradata Utility】系统工具使用

    List two ways in which a system utility can be started. Explain how to use the following utilities t ...

  8. input reset 重置时间

    经验规律,301毫秒. function autoFormatMoney() { if (!this.value.length) {return} var num = parseFloat(this. ...

  9. C#深度学习の委托深度解析

    一.我们在使用C#的过程中,不可避免的用到了委托. 委托的本质是什么呢? 从语法上看,委托是对方法的抽象封装,例如:public void print1(),public void print2(), ...

  10. UVA129-Krypton Factor(搜索剪枝)

    Problem UVA129-Krypton Factor Accept:1959  Submit:10261 Time Limit: 3000 mSec  Problem Description 通 ...