Java graphical interface, design the employee information input system interface, as shown in the figure

CSDN Q & A 2022-02-13 09:14:53 阅读数:372

java graphical interface design employee

img

img




Take the answer :
package com.eleven;import javax.swing.*;import java.awt.*;import java.util.Enumeration;/** * @author eleven * @date 2021/7/7 13:28 * @apiNote */public class Test extends JFrame { public static void main(String[] args) { Test test = new Test(); JLabel noLabel = new JLabel(" Job number :"); JTextField no = new JTextField(); JLabel nameLabel = new JLabel(" full name :"); JTextField name = new JTextField();; JLabel sexLabel = new JLabel(" Gender :"); JRadioButton man = new JRadioButton(" male "); JRadioButton woman = new JRadioButton(" Woman "); ButtonGroup group = new ButtonGroup();; group.add(man); group.add(woman); JLabel zcLabel = new JLabel(" The title :"); String[] items = new String[]{
" The engineer "," Assistant "," senior engineer "}; JComboBox comboBox = new JComboBox(items); JLabel salaryLabel = new JLabel(" Title salary "); JTextField salary = new JTextField("6000"); salary.setEditable(false); StringBuilder sb= new StringBuilder(); sb.append(" Job number \t full name \t Gender \t The title \t Wages \n"); JTextArea jTextArea = new JTextArea(); JButton addBtn = new JButton(" add to "); JButton exitBtn = new JButton(" sign out "); JPanel jPanel = new JPanel(); jPanel.setLayout(new GridLayout(6, 3)); jPanel.add(noLabel); jPanel.add(new JLabel()); jPanel.add(no); jPanel.add(nameLabel); jPanel.add(new JLabel()); jPanel.add(name); jPanel.add(sexLabel); jPanel.add(man); jPanel.add(woman); jPanel.add(zcLabel); jPanel.add(new JLabel()); jPanel.add(comboBox); jPanel.add(salaryLabel); jPanel.add(new JLabel()); jPanel.add(salary); jPanel.add(addBtn); jPanel.add(exitBtn); test.setLayout(new BorderLayout()); test.add(jPanel,BorderLayout.NORTH); jTextArea.setPreferredSize(new Dimension(400, 100)); jTextArea.setText(sb.toString()); test.add(jTextArea,BorderLayout.SOUTH); test.setTitle(" test "); test.setBounds(300, 300, 400, 300); test.setVisible(true); test.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //=========== Button event ============= exitBtn.addActionListener(e -> { System.exit(0); }); addBtn.addActionListener(e -> { String sexText = ""; Enumeration<AbstractButton> elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton btn = elements.nextElement(); if (btn.isSelected()) { sexText = btn.getText(); } } sb.append(no.getText()).append("\t") .append(name.getText()).append("\t") .append(sexText).append("\t") .append(comboBox.getSelectedItem().toString()).append("\t") .append(salary.getText()).append("\t") .append("\n"); jTextArea.setText(sb.toString()); }); comboBox.addActionListener(e -> { switch (comboBox.getSelectedIndex()){ case 2 : salary.setText("8000"); break; case 1 : salary.setText("5000"); break; case 0 : default: salary.setText("6000"); break; } }); }}

copyright:author[CSDN Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130914516307.html