[asm] sss
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- package JFram;
- import java.awt.Color;
- import java.awt.Font;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.JTextField;
- import javax.swing.table.DefaultTableModel;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class May_2 extends JFrame implements ActionListener {
- DefaultTableModel model = new DefaultTableModel();
- JLabel Lid,txt, lnameLabel, lsexLabel, position, lsalary, lphone, lesail;
- JTextField tid, lname, lsex, lposition, tsalary, tphone, temail;
- JTable table;
- JButton btsave, btupdate, btdelete;
- public May_2() {
- txt = new JLabel("Form of Employee");
- txt.setFont(new Font("", Font.BOLD,40));
- txt.setBounds(90, 20, 450, 80);
- txt.setForeground(Color.white);
- add(txt);
- Lid = new JLabel("Code");
- Lid.setFont(new Font("", Font.BOLD,20));
- Lid.setBounds(70, 140, 120, 40);
- Lid.setForeground(Color.white);
- add(Lid);
- lnameLabel = new JLabel("Name");
- lnameLabel.setFont(new Font("", Font.BOLD,20));
- lnameLabel.setBounds(70, 220, 120, 40);
- lnameLabel.setForeground(Color.white);
- add(lnameLabel);
- lsexLabel = new JLabel("Sex");
- lsexLabel.setFont(new Font("", Font.BOLD,20));
- lsexLabel.setBounds(70, 300, 120, 40);
- lsexLabel.setForeground(Color.white);
- add(lsexLabel);
- position = new JLabel("Position");
- position.setFont(new Font("", Font.BOLD,20));
- position.setBounds(70, 380, 120, 40);
- position.setForeground(Color.white);
- add(position);
- lsalary = new JLabel("Salary");
- lsalary.setFont(new Font("", Font.BOLD,20));
- lsalary.setBounds(70, 460, 120, 40);
- lsalary.setForeground(Color.white);
- add(lsalary);
- tid = new JTextField();
- tid.setFont(new Font("", Font.BOLD, 20));
- tid.setBounds(70, 180, 400, 40);
- tid.setBorder(null);
- add(tid);
- lname = new JTextField();
- lname.setFont(new Font("", Font.BOLD,20));
- lname.setBounds(70, 260, 400, 40);
- lname.setBorder(null);
- add(lname);
- lsex = new JTextField();
- lsex.setFont(new Font("", Font.BOLD, 20));
- lsex.setBounds(70, 340, 400, 40);
- lsex.setBorder(null);
- add(lsex);
- lposition = new JTextField();
- lposition.setFont(new Font("", Font.BOLD,20));
- lposition.setBounds(70, 420, 400, 40);
- lposition.setBorder(null);
- add(lposition);
- tsalary = new JTextField();
- tsalary.setFont(new Font("", Font.BOLD,20));
- tsalary.setBounds(70, 500, 400, 40);
- tsalary.setBorder(null);
- add(tsalary);
- btsave = new JButton("Save");
- btsave.setFont(new Font("", Font.BOLD,20));
- btsave.setBounds(70, 600, 120, 40);
- btsave.setForeground(Color.white);
- btsave.setBackground(Color.green);
- btsave.setBorder(null);
- add(btsave);
- btupdate = new JButton("Update");
- btupdate.setFont(new Font("", Font.BOLD, 20));
- btupdate.setBounds(220, 600, 120, 40);
- btupdate.setForeground(Color.white);
- btupdate.setBackground(Color.ORANGE);
- btupdate.setBorder(null);
- add(btupdate);
- btdelete = new JButton("Delete");
- btdelete.setFont(new Font("", Font.BOLD,20));
- btdelete.setBounds(370, 600, 120, 40);
- btdelete.setForeground(Color.white);
- btdelete.setBackground(Color.RED);
- btdelete.setBorder(null);
- add(btdelete);
- btsave.addActionListener(this);
- btupdate.addActionListener(this);
- btdelete.addActionListener(this);
- String Header[] ={"CODE", "NAME", "SEX", "POSITION","SALARY"};
- table = new JTable();
- model = new DefaultTableModel();
- model.setColumnIdentifiers(Header);
- table.setRowHeight(30);
- table.setFont(new Font("Time New Roman", Font.BOLD, 15));
- table.setModel(model);
- table.setForeground(Color.black);
- JScrollPane js = new JScrollPane(table);
- js.setBounds(550,20,600,600);
- add(js);
- initializeComponents();
- getContentPane().setBackground(Color.PINK);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLayout(null);
- setSize(1200,700);
- setVisible(true);
- setLocationRelativeTo(null);
- }
- public static void main(String[] args) {
- new May_2();
- }
- public void Clear()
- {
- tid.setText("");
- lname.setText("");
- lsex.setText("");
- lposition.setText("");
- tsalary.setText("");
- }
- public void getData() {
- model = (DefaultTableModel) table.getModel();
- model.setRowCount(0);
- List_emp.list.forEach(list -> {
- Object[] row = {
- list.getCode(),
- list.getName(),
- list.getSex(),
- list.getPosition(),
- list.getSalary()
- };
- model.addRow(row);
- });
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- if(e.getSource()==btsave){
- int code = Integer.parseInt(tid.getText());
- String name = lname.getText();
- String sex = lsex.getText();
- String position = lposition.getText();
- float salary = Float.parseFloat(tsalary.getText());
- List_emp.list.add(new List_emp(code, name, sex, position, salary));
- getData();
- Clear();
- }
- }
- private void initializeComponents() {
- }
- }
Editor
You can edit this paste and save as new: