22 April 2016

TEST ADD1 Aptech FPT 2016 Eclipse

[TEST ADD1 Aptech fpt - Eclipse]



>>Create the program<<

How to create JtextArea scrollbar Eclipse?




How to create title eclipse?

OR



userFriendly .java
 package userFriendly;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class userFriendly {

 private JFrame frame;
 private JTextField txtID;
 private JTextField txtName;
 private JTextField txtDay;

 /**
  * Launch the application.
  */
 public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
   public void run() {
    try {
     userFriendly window = new userFriendly();
     window.frame.setVisible(true);
    } catch (Exception e) {
     e.printStackTrace();
    }
   }
  });
 }

 /**
  * Create the application.
  */
 public userFriendly() {
  initialize();
  frame.setTitle("Design Preview [EmployeeLeave]");
  
 }

 /**
  * Initialize the contents of the frame.
  */
 private void initialize() {
  frame = new JFrame();
  frame.setBounds(450, 150, 488, 432);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.getContentPane().setLayout(null);
  
  JLabel lblEmployeeLeaveApplication = new JLabel("Employee Leave Application");
  lblEmployeeLeaveApplication.setFont(new Font("Tahoma", Font.BOLD, 14));
  lblEmployeeLeaveApplication.setBounds(126, 11, 221, 35);
  frame.getContentPane().add(lblEmployeeLeaveApplication);
  
  txtID = new JTextField();
  txtID.setBounds(201, 79, 116, 20);
  frame.getContentPane().add(txtID);
  txtID.setColumns(10);
  
  txtName = new JTextField();
  txtName.setBounds(201, 115, 116, 20);
  frame.getContentPane().add(txtName);
  txtName.setColumns(10);
  
  JComboBox comboBox = new JComboBox();
  comboBox.setModel(new DefaultComboBoxModel(new String[] {"SL", "LS"}));
  comboBox.setBounds(199, 157, 47, 20);
  frame.getContentPane().add(comboBox);
  
  txtDay = new JTextField();
  txtDay.setBounds(199, 201, 30, 20);
  frame.getContentPane().add(txtDay);
  txtDay.setColumns(10);
  
  JScrollPane scrollPane = new JScrollPane();
  scrollPane.setBounds(193, 243, 195, 70);
  frame.getContentPane().add(scrollPane);
  
  JTextArea textArea = new JTextArea();
  scrollPane.setViewportView(textArea);
  
  JButton btnSave = new JButton("Save");
  btnSave.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    File file = new File("E://leave_records.txt");
    if(txtID.getText().length() != 0 && txtName.getText().length() !=0 && txtDay.getText().length() != 0
      && textArea.getText().length() !=0){
    
    try {
     file.createNewFile();
     FileWriter fw  = new FileWriter(file);
     BufferedWriter bw = new BufferedWriter(fw);
     String data = txtID.getText();
     String data1 = txtName.getText();
     String data2 = txtDay.getText();
     String data3 = textArea.getText();
     String data4 = comboBox.getSelectedItem().toString();
    
     bw.write(data);
     bw.write(data1);
     bw.write(data2);
     bw.write(data3);
     bw.write(data4);
     bw.close();
     fw.close();
   
    } catch (IOException e1) {
     // TODO Auto-generated catch block
     e1.printStackTrace();
    }
    }else{
     JOptionPane.showMessageDialog(null, "Khong duoc de trong");
    }
   }
  });
  btnSave.setIcon(new ImageIcon("C:\\Users\\Lonely\\workspace\\ADD1\\icon\\Save-icon.png"));
  btnSave.setBounds(75, 332, 89, 23);
  frame.getContentPane().add(btnSave);
  
  JButton btnReset = new JButton("Reset");
  btnReset.setIcon(new ImageIcon("C:\\Users\\Lonely\\workspace\\ADD1\\icon\\Actions-edit-redo-icon.png"));
  btnReset.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    txtID.setText("");
    txtName.setText("");
    txtDay.setText("");
    textArea.setText("");
   }
  });
  btnReset.setBounds(185, 332, 89, 23);
  frame.getContentPane().add(btnReset);
  
  JButton btnExit = new JButton("Exit");
  btnExit.setIcon(new ImageIcon("C:\\Users\\Lonely\\workspace\\ADD1\\icon\\Actions-edit-delete-icon.png"));
  btnExit.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent arg0) {
    System.exit(0);
   }
  });
  btnExit.setBounds(299, 332, 89, 23);
  frame.getContentPane().add(btnExit);
  
  JLabel lblEmpId = new JLabel("Emp ID:");
  lblEmpId.setBounds(75, 79, 46, 14);
  frame.getContentPane().add(lblEmpId);
  
  JLabel lblNewLabel = new JLabel("Employee Name:");
  lblNewLabel.setBounds(75, 118, 102, 14);
  frame.getContentPane().add(lblNewLabel);
  
  JLabel lblLeaveType = new JLabel("Leave Type:");
  lblLeaveType.setBounds(75, 157, 75, 14);
  frame.getContentPane().add(lblLeaveType);
  
  JLabel lblNoOfDays = new JLabel("No of days:");
  lblNoOfDays.setBounds(75, 201, 75, 14);
  frame.getContentPane().add(lblNoOfDays);
  
  JLabel lblNewLabel_1 = new JLabel("Reason:");
  lblNewLabel_1.setBounds(75, 239, 46, 14);
  frame.getContentPane().add(lblNewLabel_1);
 }
}

 Save





Validating




Reset


Exit





Create foder icon copy pates => to foder






0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang