[asm] sss

Viewer

  1. package JFram
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7. import javax.swing.JScrollPane;
  8. import javax.swing.JTable;
  9. import javax.swing.JTextField;
  10. import javax.swing.table.DefaultTableModel;
  11. import java.awt.event.ActionEvent;
  12. import java.awt.event.ActionListener;
  13. public class May_2 extends JFrame implements ActionListener {
  14.     DefaultTableModel model = new DefaultTableModel();
  15.     JLabel Lid,txt, lnameLabel, lsexLabel, position, lsalary, lphone, lesail;
  16.     JTextField tid, lname, lsex, lposition, tsalary, tphone, temail;
  17.     JTable table;
  18.     JButton btsave, btupdate, btdelete;
  19.     public May_2() {
  20.         txt = new JLabel("Form of Employee")
  21.         txt.setFont(new Font("", Font.BOLD,40));
  22.         txt.setBounds(90, 20, 450, 80)
  23.         txt.setForeground(Color.white);
  24.         add(txt);
  25.         Lid = new JLabel("Code")
  26.         Lid.setFont(new Font("", Font.BOLD,20));
  27.         Lid.setBounds(70, 140, 120, 40)
  28.         Lid.setForeground(Color.white);
  29.         add(Lid);
  30.         lnameLabel = new JLabel("Name")
  31.         lnameLabel.setFont(new Font("", Font.BOLD,20));
  32.         lnameLabel.setBounds(70, 220, 120, 40)
  33.         lnameLabel.setForeground(Color.white);
  34.         add(lnameLabel);
  35.         lsexLabel = new JLabel("Sex");
  36.         lsexLabel.setFont(new Font("", Font.BOLD,20))
  37.         lsexLabel.setBounds(70, 300, 120, 40)
  38.         lsexLabel.setForeground(Color.white);
  39.         add(lsexLabel);
  40.         position = new JLabel("Position")
  41.         position.setFont(new Font("", Font.BOLD,20))
  42.         position.setBounds(70, 380, 120, 40)
  43.         position.setForeground(Color.white);
  44.         add(position);
  45.         lsalary = new JLabel("Salary")
  46.         lsalary.setFont(new Font("", Font.BOLD,20));
  47.         lsalary.setBounds(70, 460, 120, 40)
  48.         lsalary.setForeground(Color.white);
  49.         add(lsalary);
  50.         tid = new JTextField()
  51.         tid.setFont(new Font("", Font.BOLD, 20))
  52.         tid.setBounds(70, 180, 400, 40)
  53.         tid.setBorder(null);
  54.         add(tid);
  55.         lname = new JTextField();
  56.         lname.setFont(new Font("", Font.BOLD,20))
  57.         lname.setBounds(70, 260, 400, 40);
  58.         lname.setBorder(null);
  59.         add(lname);
  60.         lsex = new JTextField();
  61.         lsex.setFont(new Font("", Font.BOLD, 20))
  62.         lsex.setBounds(70, 340, 400, 40)
  63.         lsex.setBorder(null);
  64.         add(lsex);
  65.         lposition = new JTextField()
  66.         lposition.setFont(new Font("", Font.BOLD,20))
  67.         lposition.setBounds(70, 420, 400, 40);
  68.         lposition.setBorder(null);
  69.         add(lposition);
  70.         tsalary = new JTextField();
  71.         tsalary.setFont(new Font("", Font.BOLD,20));
  72.         tsalary.setBounds(70, 500, 400, 40);
  73.         tsalary.setBorder(null);
  74.         add(tsalary);
  75.         btsave = new JButton("Save")
  76.         btsave.setFont(new Font("", Font.BOLD,20));
  77.         btsave.setBounds(70, 600, 120, 40);
  78.         btsave.setForeground(Color.white);
  79.         btsave.setBackground(Color.green);
  80.         btsave.setBorder(null);
  81.         add(btsave);
  82.         btupdate = new JButton("Update");
  83.         btupdate.setFont(new Font("", Font.BOLD, 20))
  84.         btupdate.setBounds(220, 600, 120, 40);
  85.         btupdate.setForeground(Color.white);
  86.         btupdate.setBackground(Color.ORANGE);
  87.         btupdate.setBorder(null);
  88.         add(btupdate);
  89.         btdelete = new JButton("Delete");
  90.         btdelete.setFont(new Font("", Font.BOLD,20))
  91.         btdelete.setBounds(370, 600, 120, 40);
  92.         btdelete.setForeground(Color.white);
  93.         btdelete.setBackground(Color.RED);
  94.         btdelete.setBorder(null);
  95.         add(btdelete);
  96.         btsave.addActionListener(this);
  97.         btupdate.addActionListener(this);
  98.         btdelete.addActionListener(this);
  99.         String Header[] ={"CODE", "NAME", "SEX", "POSITION","SALARY"};
  100.         table = new JTable();
  101.         model = new DefaultTableModel();
  102.         model.setColumnIdentifiers(Header)
  103.         table.setRowHeight(30);
  104.         table.setFont(new Font("Time New Roman", Font.BOLD, 15));
  105.         table.setModel(model);
  106.         table.setForeground(Color.black);
  107.         JScrollPane js = new JScrollPane(table);
  108.         js.setBounds(550,20,600,600);
  109.         add(js);
  110.         initializeComponents();
  111.         getContentPane().setBackground(Color.PINK);
  112.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  113.         setLayout(null)
  114.         setSize(1200,700);
  115.         setVisible(true);
  116.         setLocationRelativeTo(null);
  117.     }
  118.     public static void main(String[] args) {
  119.         new May_2();
  120.     }
  121. public void Clear()
  122. {
  123. tid.setText("");
  124. lname.setText("");
  125. lsex.setText("");
  126. lposition.setText("");
  127. tsalary.setText("");
  128. }
  129. public void getData() {
  130.     model = (DefaultTableModel) table.getModel();
  131.     model.setRowCount(0);
  132.     List_emp.list.forEach(list -{
  133.         Object[] row = {
  134.             list.getCode(),
  135.             list.getName(),
  136.             list.getSex(),
  137.             list.getPosition(),
  138.             list.getSalary()
  139.         };
  140.         model.addRow(row);
  141.     });
  142. }
  143. @Override
  144. public void actionPerformed(ActionEvent e) {
  145.     if(e.getSource()==btsave){
  146.         int code = Integer.parseInt(tid.getText());
  147.         String name = lname.getText();
  148.         String sex = lsex.getText();
  149.         String position = lposition.getText();
  150.         float salary = Float.parseFloat(tsalary.getText());
  151.         List_emp.list.add(new List_emp(code, name, sex, position, salary));
  152.         getData();
  153.         Clear();
  154.         }
  155.     }
  156.     private void initializeComponents() {
  157.     }
  158. }
  159.  

Editor

You can edit this paste and save as new:


File Description
  • sss
  • Paste Code
  • 02 May-2024
  • 5.62 Kb
You can Share it: