WindowBuilder的使用----java前端的重要框架
WindowBuilder的使用----java前端的重要框架在做一些小demo的时候,需要可视化界面,需要引用swing、awt等包,需要记忆的很多。安装windowsbuilder插件可以更简单的实现java的可视化编程,利用拖拽就可以实现界面分布,不需要记忆太多,只要记住组件的用途就好。windowbuilder有两个界面,一个是sourse界面,用于编写代码和查看生成的代码。一个是desi
WindowBuilder的使用----java前端的重要框架
在做一些小demo的时候,需要可视化界面,需要引用swing、awt等包,需要记忆的很多。安装windowsbuilder插件可以更简单的实现java的可视化编程,利用拖拽就可以实现界面分布,不需要记忆太多,只要记住组件的用途就好。
windowbuilder有两个界面,一个是sourse界面,用于编写代码和查看生成的代码。一个是design界面,可视化布局区域。
design界面有几个主要用户接口,structure和palette。
structure 分成 Components:组件之间的层次关系 和properties:显示组件事件和属性。
patelle : 提供了快速便捷的组件来拖拽使用,
进入design开始制作
1、做标签
2、只可读入的文本框
3、可输入的文本框
在代码区添加输入代码
4、密码输入
5、单项选择
6、多项选择
7、下划菜单
8、给按钮添加事件监听
点击之后,会自动跳到代码区
界面跳转需要在两个类的代码里实例化
9、添加背景
选择背景团片所在位置即可
运行结果
点击确定
结语 这是一款非常好用的插件,它可以节省大量的敲打代码的时间,而且修改非常方便。
代码
package firstday;
import java.awt.EventQueue;
import javax.swing.JRadioButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JPasswordField;
import javax.swing.ImageIcon;
public class FirstDay extends JFrame {
public static FirstDay firstday1 = new FirstDay();// 实例化
private JPanel contentPane;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField;
private JPasswordField passwordField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FirstDay frame = new FirstDay();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public FirstDay() {
setFont(new Font("Bookman Old Style", Font.BOLD | Font.ITALIC, 12));
setBackground(Color.LIGHT_GRAY);
setTitle("\u5B66\u751F\u4FE1\u606F");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel label = new JLabel("学校");
label.setBounds(10, 10, 37, 15);
contentPane.add(label);
JLabel label_1 = new JLabel("学号");
label_1.setFont(new Font("宋体", Font.BOLD, 12));
label_1.setBounds(10, 53, 54, 15);
contentPane.add(label_1);
textField_1 = new JTextField();
textField_1.setBounds(82, 50, 107, 21);
contentPane.add(textField_1);
textField_1.setColumns(10);
JLabel label_2 = new JLabel("姓名");
label_2.setBounds(10, 93, 54, 15);
contentPane.add(label_2);
textField_2 = new JTextField();
textField_2.setBounds(82, 90, 107, 21);
contentPane.add(textField_2);
textField_2.setColumns(10);
JLabel label_3 = new JLabel("性别");
label_3.setBounds(10, 131, 54, 15);
contentPane.add(label_3);
JRadioButton radioButton = new JRadioButton("男");
radioButton.setBounds(83, 127, 73, 23);
contentPane.add(radioButton);
JRadioButton radioButton_1 = new JRadioButton("女");
radioButton_1.setBounds(187, 127, 88, 23);
contentPane.add(radioButton_1);
JLabel label_4 = new JLabel("爱好");
label_4.setFont(new Font("宋体", Font.BOLD, 12));
label_4.setBounds(10, 166, 54, 15);
contentPane.add(label_4);
JCheckBox checkBox = new JCheckBox("游泳");
checkBox.setBounds(84, 162, 54, 23);
contentPane.add(checkBox);
JCheckBox checkBox_1 = new JCheckBox("跑步");
checkBox_1.setBounds(140, 162, 54, 23);
contentPane.add(checkBox_1);
JCheckBox checkBox_2 = new JCheckBox("唱歌");
checkBox_2.setBounds(196, 162, 54, 23);
contentPane.add(checkBox_2);
JCheckBox checkBox_3 = new JCheckBox("篮球");
checkBox_3.setBounds(252, 162, 49, 23);
contentPane.add(checkBox_3);
JComboBox comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(new String[] {"计科", "软工", "智科", "信安", "信抗"}));
comboBox.setBounds(83, 202, 72, 21);
contentPane.add(comboBox);
JLabel label_5 = new JLabel("专业");
label_5.setFont(new Font("宋体", Font.BOLD, 12));
label_5.setForeground(new Color(51, 51, 0));
label_5.setBounds(10, 205, 37, 15);
contentPane.add(label_5);
JButton button = new JButton("\u767B\u5F55");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {//事件接听
String id = textField_1.getText();
String pass = passwordField.getText();
System.out.println(id);
System.out.println(pass);
if (id.equals("1900300101") && pass.equals("1900300101")) {//没有连接数据库,直接定义账号密码均为1900300101
JOptionPane.showMessageDialog(null, "登录成功");//提示框
firstday1.setVisible(false);//实现界面跳转
Enter.enter.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null, "登录失败");
}
}
});
button.setBounds(152, 233, 124, 23);
contentPane.add(button);
textField = new JTextField();
textField.setText("桂林电子科技大学");
textField.setBounds(72, 7, 107, 21);
contentPane.add(textField);
textField.setColumns(10);
passwordField = new JPasswordField();
passwordField.setBounds(306, 50, 118, 21);
contentPane.add(passwordField);
JLabel lblNewLabel = new JLabel("\u5BC6\u7801");
lblNewLabel.setFont(new Font("宋体", Font.BOLD, 12));
lblNewLabel.setBounds(258, 53, 37, 15);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("New label");
lblNewLabel_1.setIcon(new ImageIcon("C:\\Users\\MeiMei\\Desktop\\2.jpg"));
lblNewLabel_1.setBounds(0, 0, 434, 256);
contentPane.add(lblNewLabel_1);
}
}
package firstday;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.ImageIcon;
public class Enter extends JFrame {
public static Enter enter = new Enter();// 实例化
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Enter frame = new Enter();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Enter() {
setTitle("\u767B\u5F55\u7ED3\u679C");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("\u606D\u559C\u4F60\u767B\u5F55\u6210\u529F\uFF01\uFF01\uFF01");
lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
lblNewLabel.setBounds(151, 23, 200, 36);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("New label");
lblNewLabel_1.setIcon(new ImageIcon("C:\\Users\\MeiMei\\Desktop\\1.jpg"));
lblNewLabel_1.setBounds(0, 0, 434, 261);
contentPane.add(lblNewLabel_1);
}
}
更多推荐
所有评论(0)