import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.border.*;
/*Download by http://www.codefans.net*/
public class BorderDemo extends JFrame implements ActionListener {
// Declare a label for displaying message
private JLabel jLabel = new JLabel("Display the border type");
// A check box for selecting a border with or without a title
private JCheckBox jchkTitled;
// Radio buttons for border styles
private JRadioButton jrbLoweredBevel, jrbRaisedBevel, jrbEtched, jrbLine,
jrbMatte, jrbEmpty;
// Radio buttons for titled border options
private JRadioButton jrbAboveBottom, jrbBottom, jrbBelowBottom,
jrbAboveTop, jrbTop, jrbBelowTop, jrbLeft, jrbCenter, jrbRight;
// TitledBorder for the label
private TitledBorder labelBorder;
/** Constructor */
public BorderDemo() {
setTitle("BorderDemo");
// Create a JLabel instance and set colors
jLabel.setBackground(Color.yellow);
jLabel.setBorder(labelBorder);
// Place title position radio buttons
JPanel jpPosition = new JPanel();
jpPosition.setLayout(new GridLayout(3, 2));
jpPosition.add(jrbAboveBottom = new JRadioButton("ABOVE_BOTTOM"));
jpPosition.add(jrbAboveTop = new JRadioButton("ABOVE_TOP"));
jpPosition.add(jrbBottom = new JRadioButton("BOTTOM"));
jpPosition.add(jrbTop = new JRadioButton("TOP"));
jpPosition.add(jrbBelowBottom = new JRadioButton("BELOW_BOTTOM"));
jpPosition.add(jrbBelowTop = new JRadioButton("BELOW_TOP"));
jpPosition.setBorder(new TitledBorder("Position"));
// Place title justification radio buttons
JPanel jpJustification = new JPanel();
jpJustification.setLayout(new GridLayout(3, 1));
jpJustification.add(jrbLeft = new JRadioButton("LEFT"));
jpJustification.add(jrbCenter = new JRadioButton("CENTER"));
jpJustification.add(jrbRight = new JRadioButton("RIGHT"));
jpJustification.setBorder(new TitledBorder("Justification"));
// Create panel jpTitleOptions to hold jpPosition and
// jpJustification
JPanel jpTitleOptions = new JPanel();
jpTitleOptions.setLayout(new BorderLayout());
jpTitleOptions.add(jpPosition, BorderLayout.CENTER);
jpTitleOptions.add(jpJustification, BorderLayout.EAST);
// Create Panel jpTitle to hold a check box and title position
// radio buttons, and title justification radio buttons
JPanel jpTitle = new JPanel();
jpTitle.setBorder(new TitledBorder("Border Title"));
jpTitle.setLayout(new BorderLayout());
jpTitle.add(jchkTitled = new JCheckBox("Titled"), BorderLayout.NORTH);
jpTitle.add(jpTitleOptions, BorderLayout.CENTER);
// Group radio buttons for title position
ButtonGroup btgTitlePosition = new ButtonGroup();
btgTitlePosition.add(jrbAboveBottom);
btgTitlePosition.add(jrbBottom);
btgTitlePosition.add(jrbBelowBottom);
btgTitlePosition.add(jrbAboveTop);
btgTitlePosition.add(jrbTop);
btgTitlePosition.add(jrbBelowTop);
// Group radio buttons for title justification
ButtonGroup btgTitleJustification = new ButtonGroup();
btgTitleJustification.add(jrbLeft);
btgTitleJustification.add(jrbCenter);
btgTitleJustification.add(jrbRight);
// Create Panel jpBorderStyle to hold border style radio buttons
JPanel jpBorderStyle = new JPanel();
jpBorderStyle.setBorder(new TitledBorder("Border Style"));
jpBorderStyle.setLayout(new GridLayout(6, 1));
jpBorderStyle.add(jrbLoweredBevel = new JRadioButton("Lowered Bevel"));
jpBorderStyle.add(jrbRaisedBevel = new JRadioButton("Raised Bevel"));
jpBorderStyle.add(jrbEtched = new JRadioButton("Etched"));
jpBorderStyle.add(jrbLine = new JRadioButton("Line"));
jpBorderStyle.add(jrbMatte = new JRadioButton("Matte"));
jpBorderStyle.add(jrbEmpty = new JRadioButton("Empty"));
// Group radio buttons for border styles
ButtonGroup btgBorderStyle = new ButtonGroup();
btgBorderStyle.add(jrbLoweredBevel);
btgBorderStyle.add(jrbRaisedBevel);
btgBorderStyle.add(jrbEtched);
btgBorderStyle.add(jrbLine);
btgBorderStyle.add(jrbMatte);
btgBorderStyle.add(jrbEmpty);
// Create Panel jpAllChoices to place jpTitle and jpBorderStyle
JPanel jpAllChoices = new JPanel();
jpAllChoices.setLayout(new BorderLayout());
jpAllChoices.add(jpTitle, BorderLayout.CENTER);
jpAllChoices.add(jpBorderStyle, BorderLayout.EAST);
// Place panels in the frame
getContentPane().setLayout(new BorderLayout());
getContentPane().add(jLabel, BorderLayout.CENTER);
getContentPane().add(jpAllChoices, BorderLayout.SOUTH);
// Register listeners
jchkTitled.addActionListener(this);
jrbAboveBottom.addActionListener(this);
jrbBottom.addActionListener(this);
jrbBelowBottom.addActionListener(this);
jrbAboveTop.addActionListener(this);
jrbTop.addActionListener(this);
jrbBelowTop.addActionListener(this);
jrbLeft.addActionListener(this);
jrbCenter.addActionListener(this);
jrbRight.addActionListener(this);
jrbLoweredBevel.addActionListener(this);
jrbRaisedBevel.addActionListener(this);
jrbLine.addActionListener(this);
jrbEtched.addActionListener(this);
jrbMatte.addActionListener(this);
jrbEmpty.addActionListener(this);
}
/** Handle ActionEvents on check box and radio buttons */
public void actionPerformed(ActionEvent e) {
// Get border style
Border border = new EmptyBorder(2, 2, 2, 2);
if (jrbLoweredBevel.isSelected()) {
border = new BevelBorder(BevelBorder.LOWERED);
jLabel.setText("Lowered Bevel Style");
} else if (jrbRaisedBevel.isSelected()) {
border = new BevelBorder(BevelBorder.RAISED);
jLabel.setText("Raised Bevel Style");
} else if (jrbEtched.isSelected()) {
border = new EtchedBorder();
jLabel.setText("Etched Style");
} else if (jrbLine.isSelected()) {
border = new LineBorder(Color.black, 5);
jLabel.setText("Line Style");
} else if (jrbMatte.isSelected()) {
border = new MatteBorder(15, 15, 15, 15, new ImageIcon(
"image/caIcon.gif"));
jLabel.setText("Matte Style");
} else if (jrbEmpty.isSelected()) {
border = new EmptyBorder(2, 2, 2, 2);
jLabel.setText("Empty Style");
}
if (jchkTitled.isSelected()) {
// Get the title position and justification
int titlePosition = TitledBorder.DEFAULT_POSITION;
int titleJustification = TitledBorder.DEFAULT_JUSTIFICATION;
if (jrbAboveBottom.isSelected())
titlePosition = TitledBorder.ABOVE_BOTTOM;
else if (jrbBottom.isSelected())
titlePosition = TitledBorder.BOTTOM;
else if (jrbBelowBottom.isSelected())
titlePosition = TitledBorder.BELOW_BOTTOM;
else if (jrbAboveTop.isSelected())
titlePosition = TitledBorder.ABOVE_TOP;
else if (jrbTop.isSelected())
titlePosition = TitledBorder.TOP;
else if (jrbBelowTop.isSelected())
titlePosition = TitledBorder.BELOW_TOP;
if (jrbLeft.isSelected())
titleJustification = TitledBorder.LEFT;
else if (jrbCenter.
没有合适的资源?快使用搜索试试~ 我知道了~
Java 创建图形用户界面例子集
共91个文件
class:38个
gif:28个
java:21个
需积分: 10 17 下载量 148 浏览量
2010-08-19
10:55:45
上传
评论
收藏 123KB RAR 举报
温馨提示
Java 创建图形用户界面例子集,学习用Java创建窗体按钮、图标、按下图标和翻转图标、复选框、单选按钮、标签、文本域、、组合框、列表框、滚动条、滑动块、创建多个窗口以及元素对齐等方面的知识技巧。
资源推荐
资源详情
资源评论
收起资源包目录
javaform.rar (91个子文件)
codefans.net
Java创建图形用户界面
.project 380B
bin
Loan.class 2KB
RadioButtonDemo$3.class 805B
ScrollBarDemo$2.class 1KB
JOptionPaneDemo.class 3KB
RadioButtonDemo$2.class 806B
InputTypeDemo.class 2KB
MenuItemListener.class 1008B
ScrollBarDemo$1.class 1KB
RadioButtonDemo$1.class 804B
TextFieldDemo$1.class 879B
MenuDemo.class 5KB
TextAreaDemo.class 2KB
CheckBoxDemo$2.class 640B
CheckBoxDemo.class 2KB
ButtonDemo.class 2KB
ButtonDemo$2.class 690B
MenuDemoNew.class 3KB
SliderDemo$2.class 996B
ListDemo.class 3KB
CheckBoxDemo$1.class 840B
ButtonDemo$1.class 689B
DescriptionPanel.class 2KB
RadioButtonDemo.class 2KB
OptionTypeDemo.class 756B
TestButtonTextPosition.class 1KB
MessgeTypeDemo.class 1KB
MessagePanel.class 3KB
SliderDemo$1.class 995B
TestButtonIcons.class 1KB
TestButtonAlignment.class 1KB
ComboBoxDemo$1.class 777B
ComboBoxDemo.class 3KB
BorderDemo.class 6KB
TextFieldDemo.class 1KB
ListDemo$1.class 1KB
SliderDemo.class 2KB
CheckBoxDemo$3.class 640B
ScrollBarDemo.class 2KB
.settings
org.eclipse.jdt.core.prefs 4KB
image
left.gif 118B
ca.gif 2KB
caIcon.gif 110B
norway.gif 1KB
right.gif 119B
flag8.gif 798B
print.gif 892B
flag9.gif 2KB
fr.gif 1KB
usIcon.gif 116B
flag5.gif 2KB
flag2.gif 3KB
china.gif 798B
flag6.gif 1KB
new.gif 364B
denmark.gif 856B
flag3.gif 1KB
grapes.gif 3KB
india.gif 1KB
Thumbs.db 57KB
flag7.gif 856B
germany.gif 2KB
flag1.gif 2KB
ico-arrow.gif 9KB
ukIcon.gif 133B
flag4.gif 1KB
us.gif 2KB
uk.gif 3KB
open.gif 578B
src
InputTypeDemo.java 1KB
SliderDemo.java 2KB
MessgeTypeDemo.java 933B
OptionTypeDemo.java 673B
ScrollBarDemo.java 2KB
MenuDemo.java 5KB
CheckBoxDemo.java 2KB
TestButtonTextPosition.java 1KB
TestButtonIcons.java 807B
Loan.java 2KB
TextAreaDemo.java 4KB
ComboBoxDemo.java 3KB
ButtonDemo.java 2KB
RadioButtonDemo.java 2KB
TestButtonAlignment.java 854B
BorderDemo.java 9KB
MessagePanel.java 3KB
TextFieldDemo.java 1KB
JOptionPaneDemo.java 3KB
MenuDemoNew.java 3KB
ListDemo.java 3KB
.classpath 232B
共 91 条
- 1
资源评论
yulongsheng123
- 粉丝: 3
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- cc test for cc
- 蚁群算法基于matlab实现,有源代码,和详细的说明文件,matlab仿真的数据及参数输入的值都一给定好
- 20231201HlBwnVr1.zip
- 基于py+matlab MATLAB实时数字图像相关软件用于监测在康奈尔高能同步加速器上进行的原位机械加载高能x射线衍射
- 基于matlab实现字符识别的参考程序,用所用的字体识别率挺高,部分手写的也能识别,但是还不能识别扭曲和倾斜的字符 .rar
- 基于matlab实现指纹识别系统 包括数据库导入、图像选择识别、帮助功能、识别图像可视、gabor滤波可视,实现界面操作.rar
- 基于matlab实现指纹识别,利用gabor滤波器,提取指纹特征,只能呢读取bmp图像.rar
- 基于matlab实现于数字图像相关方法中散斑质量评价
- 基于matlab实现遗传算法和佳点集遗传算法的基本思想和不同点,用遗传算法测试一标准函数 佳点集算法测试一标准函数
- tensorflow-gpu-2.5.1-cp38-cp38-manylinux2010-x86-64.whl
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功