当前位置:网站首页>Basic components and intermediate components
Basic components and intermediate components
2022-07-03 07:00:00 【Bugxiu_ fu】
package com.zking.test;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class BaseComponentDemo extends JFrame{
/**
* Basic components
* 1. classification : Input box ( Account box , Password box ), Button , Text label , Text domain , File selector , Radio buttons , Check box , A drop-down box
* 2. effect : Beautify the form
* 3. Usage mode
* (1)api Look up the specified component name and instantiate
* (2) Add the instantiated basic component to the intermediate component
* (3) Add intermediate components to the form ( Top level components ) in .
* 4. Specific basic components
* JLabel Text label
* JButtom Button
* JRadioBuccon Radio button
* JCheckBox Check button
* JTextField Normal text input box
* JPasswordField Password box
* JComboBox Drop down box component
* JTextArea Text domain
* JFileChooser File selector
*
* 5. Intermediate components
* JPanel panel The highest usage rate
* JScrollPane Scroll panel
*/
public BaseComponentDemo() {
this.setTitle(" Basic components ");
this.setSize(600, 500);
this.setDefaultCloseOperation(3);
this.setLocationRelativeTo(null);
// Create intermediate components JPanel panel
JPanel jpanel = new JPanel();
// Set up jpanel The background color of the panel
jpanel.setBackground(Color.PINK);
// -------------------- Add basic components to intermediate components -------------------------------
/**
* 1.api Look up the specified component name and instantiate 2. Add the instantiated basic component to the intermediate component
*/
/**
* label JLabel
*/
// 1.api Look up the specified component name and instantiate
JLabel jla = new JLabel(" The user login ");
// Set font size ( In bold , style )
jla.setFont(new Font(" Chinese Xingkai ", Font.BOLD, 30));
// Set font color
jla.setForeground(Color.YELLOW);
// Set up jla The border line of the component
jla.setBorder(BorderFactory.createLineBorder(Color.blue));
// Setting the background is invalid jla.setBackground(Color.red);
// 2. Add the instantiated basic component to the intermediate component
jpanel.add(jla);
//---------------------------------------------------
/**
* Button JButton Button constructor : 1. You can pass in a string 2. You can import pictures
*/
JButton jba = new JButton(" Sign in ");
// jba.setEnabled(false); // The setting button cannot be edited
// Set the size of the button
jba.setPreferredSize(new Dimension(500, 50));
// Set font size
jba.setFont(new Font(" Song style ", Font.BOLD, 30));
// Set the background
jba.setBackground(Color.green);
// Set the mouse gesture
jba.setCursor(new Cursor(Cursor.HAND_CURSOR));
jpanel.add(jba);
//---------------------------------------------------
/**
* Normal text input box JTextField
*/
JTextField jtfa = new JTextField(15);
jpanel.add(jtfa);
/**
* Password input box JPasswordField
*/
JPasswordField jpfa = new JPasswordField(15);
jpanel.add(jpfa);
/**
* Radio button JRadioButton
* matters needing attention : When using radio button components in a form , You must combine multiple objects into a group , Only one can be selected in a group
*
* Radio button grouping : ButtonGroup
*/
JRadioButton jrba = new JRadioButton(" male ");
JRadioButton jrbb = new JRadioButton(" Woman ");
// Create grouping objects
ButtonGroup bg = new ButtonGroup();
// Add the radio button to the grouping object
bg.add(jrba);
bg.add(jrbb);
jpanel.add(jrba);
jpanel.add(jrbb);
/**
* Check button JCheckBox
*/
JCheckBox jcba = new JCheckBox(" having dinner ");
JCheckBox jcbb = new JCheckBox(" Hit Kangkang ");
JCheckBox jcbc = new JCheckBox(" See a movie ");
JCheckBox jcbd = new JCheckBox(" Hammer Kangkang ");
JCheckBox jcbe = new JCheckBox(" Sleep well ");
jpanel.add(jcba);
jpanel.add(jcbb);
jpanel.add(jcbc);
jpanel.add(jcbd);
jpanel.add(jcbe);
/**
* A drop-down box JComboBox
*/
JComboBox jcbaa = new JComboBox();
// Pull down the box to load data
jcbaa.addItem(" Kang Kang ");
jcbaa.addItem(" Travel ");
jcbaa.addItem(" Wang Wang ");
jcbaa.addItem(" Jun Jun ");
jcbaa.addItem(" Ye ye ");
jcbaa.addItem(" Wen Wen ");
jpanel.add(jcbaa);
/**
* Text domain JTextArea
*/
JTextArea jtaa = new JTextArea(5, 50);
// problem : After the content increases , Text y The height of the domain will overflow .
// Load scroll bar
/**
* Instantiate a scroll bar panel ( Intermediate components ) JScrollPane
*/
JScrollPane jsp = new JScrollPane(jtaa);
jpanel.add(jsp);
/**
* File selector JFileChooser
*/
JFileChooser jfc = new JFileChooser();
jpanel.add(jfc);
// After getting the form jpanel The middle component panel is added
this.getContentPane().add(jpanel);
this.setVisible(true);
}
public static void main(String[] args) {
new BaseComponentDemo();
/**
* JLabel
* JButton
* JTextField
* JPasswordField
* JRadioButton|ButtonGroup
* JCheckBox
* JComboBox
* JScrollPane
* JTextArea
* JFileChooser
*/
}
}
边栏推荐
- [vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)
- Resttemplate configuration use
- Software testing learning - the next day
- (翻译)异步编程:Async/Await在ASP.NET中的介绍
- php安装composer
- 机器学习 | 简单但是能提升模型效果的特征标准化方法(RobustScaler、MinMaxScaler、StandardScaler 比较和解析)
- JMeter test result output
- Integration test practice (1) theoretical basis
- 萬卷書 - 價值投資者指南 [The Education of a Value Investor]
- [attribute comparison] defer and async
猜你喜欢
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
Pytest -- write and manage test cases
多个全局异常处理类,怎么规定执行顺序
Pits encountered in the use of El checkbox group
On the practice of performance optimization and stability guarantee
Win 10 find the port and close the port
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
Create your own deep learning environment with CONDA
Setting up the development environment of dataworks custom function
How to specify the execution order for multiple global exception handling classes
随机推荐
centos php7.2.24升级到php7.3
Flask Foundation
Laravel frame step pit (I)
IC_EDA_ALL虚拟机(丰富版):questasim、vivado、vcs、verdi、dc、pt、spyglass、icc2、synplify、INCISIVE、IC617、MMSIM、工艺库
Machine learning | simple but feature standardization methods that can improve the effect of the model (comparison and analysis of robustscaler, minmaxscaler, standardscaler)
La loi des 10 000 heures ne fait pas de vous un maître de programmation, mais au moins un bon point de départ
Basic teaching of crawler code
[day15] introduce the features, advantages and disadvantages of promise, and how to implement it internally. Implement promise by hand
修改MySQL密码
Getting started with pytest
The education of a value investor
爬虫代码基础教学
2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)
Laravel Web Framework
[untitled]
CentOS switches and installs mysql5.7 and mysql8.0
Understand software testing
Centos切换安装mysql5.7和mysql8.0
每日刷題記錄 (十一)
What are the characteristics and functions of the scientific thinking mode of mechanical view and system view