JFrame2
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的更多相关文章
随机推荐
- 运行 python *.py 文件出错,如:python a.py
运行 python *.py 文件出错,如:python a.py(下图) 原因:没有安装web.py 解决:下载并安装 网址:http://webpy.org/install#install (h ...
- TeamViewer试用期满转免费版本方法
TeamViewer安装完企业版以后,当试用期结束,到期后,无论你卸载.重装了多少次,都无法无法成功安装个人版,从网上搜索来得到的解决办法就是:安装TeamViewer的时候与你的电脑以及网卡地址进行 ...
- 转载:如何在Ubuntu 18.04上使用UFW设置防火墙
https://blog.csdn.net/u013068789/article/details/82051943 介绍 UFW或Uncomplicated Firewall是iptables一个接口 ...
- Linux重命名网卡名称
1.查看当前网卡: nmcli connection show 可以看到我有两个网卡,其中一个为中文名称,我想将配置 2 修改为net-DHCP 2.cd到/etc/sysconfig/network ...
- The server principal "sa" is not able to access the database "xxxx" under the current security context
在SQL Server服务器上一个作业执行时,遇到下面错误信息: Message: Executed as user: dbo. The server principal "sa" ...
- spring4笔记----PropertyOverrideConfigureer 重写占位符配置器(图)
- 使用html+css+js实现简易计算器
使用html+css+js实现简易计算器, 效果图如下: html代码如下: <!DOCTYPE html> <html lang="en"> <he ...
- 以太坊 ERC20 与 ERC721 深度解密
去年11月份的一段时间,Ethereum网络突然变的特别拥堵,原因是兴起了一款以太坊养猫的Dapp游戏,超级可爱的猫形象,再加上配种,繁殖和拍卖等丰富的玩法,风靡了币圈. 一时间币圈大大小小的人都在撸 ...
- 初识Spring Boot
1.Spring Boot简介 Spring Boot是由Pivotal团队提供的全新框架,用于简化基于Spring的搭建与开发过程,通过少量的代码创建Spring应用. 2.Spring Boo ...
- Unity的AssetDatabase路径格式
开发环境 windows 7 Unity 5.3 及更高版本 前言 使用AssetDatabase.Load或AnimatorController.CreateAnimatorControllerAt ...