1.java做一个注册界面
import javax.swing.*;
import java.awt.*;
public class ResisterUI {
public void initLoginUI() {
JFrame frame = new JFrame();
frame.setTitle("注册界面");
frame.setSize(400, 600);
frame.setLocation(700, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flowLayout = new FlowLayout();
frame.setLayout (flowLayout);
JButton button = new JButton("注册");
JLabel nameJla = new JLabel("昵称:");
JTextField nameJtx = new JTextField();
JLabel pwdJla = new JLabel("密码:");
JPasswordField pwdJpf = new JPasswordField();
JLabel phoneJla = new JLabel("手机号码:");
JTextField phoneJtx = new JTextField();
Dimension dim = new Dimension(310, 35);
nameJtx.setPreferredSize(dim);
pwdJpf.setPreferredSize(dim);
phoneJtx.setPreferredSize(dim);
ImageIcon imageIcon = new ImageIcon ("C:\\Users\\35320\\Desktop\\aaa.jpg");
JLabel imageJla = new JLabel(imageIcon);
frame.add(nameJla);
frame.add(nameJtx);
frame.add(pwdJla);
frame.add(pwdJpf);
frame.add(phoneJla);
frame.add(phoneJtx);
frame.add(button);
frame.add(imageJla);
frame.setVisible(true);
}
public static void main(String[] args){
ResisterUI ui = new ResisterUI();
ui.initLoginUI();
}
}
运行截图
2.java做一个计算器界面
import javax.swing.*;
import java.awt.*;
public class CalculatorUI {
public void initLoginUI() {
JFrame frame = new JFrame();
frame.setTitle("计算器界面");
frame.setSize(360, 530);
frame.setLocation(700, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FlowLayout flowLayout = new FlowLayout();
frame.setLayout (flowLayout);
JButton button1 = new JButton("AC");
JButton button2 = new JButton("DEL");
JButton button3 = new JButton("(");
JButton button4 = new JButton(")");
JButton button5 = new JButton("/");
JButton button6 = new JButton("7");
JButton button7 = new JButton("8");
JButton button8 = new JButton("9");
JButton button9 = new JButton("+");
JButton button10 = new JButton("4");
JButton button11 = new JButton("5");
JButton button12 = new JButton("6");
JButton button13 = new JButton("-");
JButton button14 = new JButton("1");
JButton button15 = new JButton("2");
JButton button16 = new JButton("3");
JButton button17 = new JButton("x");
JButton button18 = new JButton("0");
JButton button19 = new JButton(".");
JButton button20 = new JButton("=");
JTextField nameJtx = new JTextField();
JPasswordField pwdJpf = new JPasswordField();
Dimension dim1 = new Dimension(315, 70);
Dimension dim2 = new Dimension(59, 60);
Dimension dim3 = new Dimension(75, 60);
Dimension dim4 = new Dimension(155, 60);
nameJtx.setPreferredSize(dim1);
pwdJpf.setPreferredSize(dim1);
button1.setPreferredSize(dim2);
button2.setPreferredSize(dim2);
button3.setPreferredSize(dim2);
button4.setPreferredSize(dim2);
button5.setPreferredSize(dim2);
button6.setPreferredSize(dim3);
button7.setPreferredSize(dim3);
button8.setPreferredSize(dim3);
button9.setPreferredSize(dim3);
button10.setPreferredSize(dim3);
button11.setPreferredSize(dim3);
button12.setPreferredSize(dim3);
button13.setPreferredSize(dim3);
button14.setPreferredSize(dim3);
button15.setPreferredSize(dim3);
button16.setPreferredSize(dim3);
button17.setPreferredSize(dim3);
button18.setPreferredSize(dim4);
button19.setPreferredSize(dim3);
button20.setPreferredSize(dim3);
frame.add(nameJtx);
frame.add(pwdJpf);
frame.add(button1);
frame.add(button2);
frame.add(button3);
frame.add(button4);
frame.add(button5);
frame.add(button6);
frame.add(button7);
frame.add(button8);
frame.add(button9);
frame.add(button10);
frame.add(button11);
frame.add(button12);
frame.add(button13);
frame.add(button14);
frame.add(button15);
frame.add(button16);
frame.add(button17);
frame.add(button18);
frame.add(button19);
frame.add(button20);
frame.setVisible(true);
}
public static void main(String[] args){
CalculatorUI ui = new CalculatorUI();
ui.initLoginUI();
}
}
运行截图