java Long

package thamgiataphuan;

import java.io.*;

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.event.*;

/**

*

* @author HACKER

*/

public final class ThamGiaTapHuan extends JFrame{

//vung 2

JLabel lbTGTH=new JLabel("THAM GIA TAP HUAN");

JLabel lbMaSV= new JLabel("Ma Sinh Vien");

JLabel lbHoTen=new JLabel("Ho Ten");

JLabel lbGioiTinh= new JLabel("Gioi Tinh");

JLabel lbGhiChu=new JLabel("Ghi Chu");

JLabel lbSoLuong=new JLabel("So Luong");

JLabel lbSL=new JLabel("0");

DefaultComboBoxModel dcmMaSV= new DefaultComboBoxModel();

JComboBox cmMaSV= new JComboBox(dcmMaSV);

DefaultListModel dlm=new DefaultListModel();

JList lsDS= new JList(dlm);

JTextField tfHoTen= new JTextField();

JTextField tfGhiChu= new JTextField();

JButton btThem= new JButton("Them");

JButton btXoa= new JButton("Xoa");

JButton btXuat= new JButton("Xuat");

JButton btThoat= new JButton("Thoat");

ButtonGroup btnGPhai=new ButtonGroup();

JRadioButton rdNam=new JRadioButton("Nam");

JRadioButton rdNu=new JRadioButton("Nữ");

ButtonGroup btGioiTinh=new ButtonGroup();

public ThamGiaTapHuan(){

super("Tham gia tap huan");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Container c= this.getContentPane();

//vung3

setLayout(new GridBagLayout());

GridBagConstraints gc= new GridBagConstraints();

gc.gridx=0;

gc.gridy=0;

gc.gridwidth=3;

c.add(lbTGTH,gc);

gc.gridwidth=1;

gc.gridx=0;

gc.gridy=1;

c.add(lbMaSV,gc);

gc.gridx=1;

gc.gridy=1;

gc.weightx=1;

gc.anchor=GridBagConstraints.WEST;

gc.fill=GridBagConstraints.BOTH;

c.add(cmMaSV,gc);

gc.weightx=0;

gc.gridx=2;

gc.gridy=1;

JPanel p1= new JPanel(new FlowLayout(FlowLayout.LEFT));

p1.add(btThem);

p1.add(btXoa);

c.add(p1,gc);

gc.gridx=0;

gc.gridy=2;

c.add(lbHoTen,gc);

gc.gridx=1;

gc.gridy=2;

gc.gridwidth=2;

gc.fill=GridBagConstraints.BOTH;

c.add(tfHoTen,gc);

gc.gridwidth=1;

gc.gridx=0;

gc.gridy=3;

c.add(lbGioiTinh,gc);

gc.gridx=1;

gc.gridy=3;

c.add(rdNam,gc);

gc.gridx=1;

gc.gridy=4;

c.add(rdNu,gc);

gc.gridx=0;

gc.gridy=5;

c.add(lbGhiChu,gc);

gc.gridx=1;

gc.gridy=5;

gc.gridwidth=2;

c.add(tfGhiChu,gc);

gc.gridwidth=1;

gc.gridx=0;

gc.gridy=6;

gc.gridwidth=3;

gc.weighty=1;

JScrollPane ps1=new JScrollPane(lsDS,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

c.add(ps1,gc);

gc.gridwidth=1;

gc.weighty=0;

gc.gridx=0;

gc.gridy=7;

JPanel p3=new JPanel(new FlowLayout());

p3.add(lbSoLuong,gc);

p3.add(lbSL,gc);

c.add(p3,gc);

gc.gridx=2;

gc.gridy=7;

JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT));

p2.add(btXuat);

p2.add(btThoat);

c.add(p2,gc);

//vung4

//cmMaSV.addItemListener(new XuLyMASV());

btThoat.addActionListener(new XuLyThoat());

btThem.addActionListener(new XuLyThem());

//vung 5

docfile();

tfHoTen.setEnabled(false);

rdNam.setEnabled(false);

rdNu.setEnabled(false);

btGioiTinh.add(rdNam);

btGioiTinh.add(rdNu);

setSize(500,400);

setVisible(true);

}

//vung6

// class XuLyMaSV implements ItemListener{

//

// @Override

// public void itemStateChanged(ItemEvent e) {

// SinhVien sv=(SinhVien)cmMaSV.getSelectedItem();

// tfHoTen.setText(sv.HoTen);

// if(sv.phai){

// rdNam.setSelected(true);

// }else{

// rdNu.setSelected(true);

// }

// }

//

// }

class XuLyThoat implements ActionListener{

public void actionPerformed(ActionEvent e){

System.exit(0);

}

}

class XuLyThem implements ActionListener{

public void actionPerformed(ActionEvent e){

SinhVien sv=(SinhVien) cmMaSV.getSelectedItem();

TapHuan th=new TapHuan(sv);

th.GhiChu=tfGhiChu.getText();

dlm.addElement(th);

lbSL.setText(""+dlm.getSize()); }

}

public static void main(String[] args) {

new ThamGiaTapHuan();

}

//vung7

void docfile(){

JFileChooser fc= new JFileChooser();

if(fc.showOpenDialog(null)==fc.CANCEL_OPTION){

return;

}

File selecFile=fc.getSelectedFile();

try{

BufferedReader br=new BufferedReader(new FileReader(selecFile));

String;

while( (tmp=br.readLine())!=null)

{

StringTokenizer token=new StringTokenizer(tmp,"_");

SinhVien sv=new SinhVien();

sv.MaSV=token.nextToken();

sv.HoTen=token.nextToken();

dcmMaSV.addElement(sv.MaSV);

}

}catch(Exception e){

System.out.println("Loi doc file,hay mo file moi");

}

}

}

Bạn đang đọc truyện trên: AzTruyen.Top

Tags: #long