当前位置:网站首页>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
*/
}
}
边栏推荐
- The dynamic analysis and calculation of expressions are really delicious for flee
- centos php7.2.24升级到php7.3
- Software testing learning - day 3
- golang操作redis:写入、读取hash类型数据
- How can I split a string at the first occurrence of “-” (minus sign) into two $vars with PHP?
- 卡特兰数(Catalan)的应用场景
- The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
- Inno Setup 制作安装包
- Search engine Bing Bing advanced search skills
- Integration test practice (1) theoretical basis
猜你喜欢

dataworks自定义函数开发环境搭建

The dynamic analysis and calculation of expressions are really delicious for flee

多个全局异常处理类,怎么规定执行顺序

Use the jvisualvm tool ----- tocmat to start JMX monitoring

vmware虚拟机C盘扩容

POI excel percentage

每日刷題記錄 (十一)

Winter vacation work of software engineering practice

Win 10 find the port and close the port

Mise en place d'un environnement de développement de fonctions personnalisées
随机推荐
Asynchronous programming: async/await in asp Net
RestHighLevelClient获取某个索引的mapping
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
Practical plug-ins in idea
万卷书 - 价值投资者指南 [The Education of a Value Investor]
golang操作redis:写入、读取kv数据
保险公司怎么查高血压?
Win 10 find the port and close the port
Unittest attempt
Centos切换安装mysql5.7和mysql8.0
[C /vb.net] convert PDF to svg/image, svg/image to PDF
C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
php安装composer
C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
Modify MySQL password
2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)
Mise en place d'un environnement de développement de fonctions personnalisées
【code】偶尔取值、判空、查表、验证等
JMeter test result output
Winter vacation work of software engineering practice