Mini3

Run Settings
LanguageJava
Language Version
Run Command
package mini_excelVersion2_refactoring; import java.awt.Dimension; import java.awt.FileDialog; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JTabbedPane; class ViewFrame extends JFrame implements ActionListener{ private Information information = null; private Excel excel = null; private Dimension screen; //�޴��� ���� private JMenuBar mb; private JMenu newFile; private JMenuItem select; private JMenu help; private JMenuItem about; private JDialog dg; private FileDialog fdg; //��ȭ�� ���� private JTabbedPane jtab = null; private JPanelBefore jpBefore = null; private JPanelName jpName = null; private JPanelList jpList = null; private JPanelText jpText = null; private JPanelClass c1 = null; private JPanelClass c2 = null; private JPanelClass c3 = null; private JPanelClass c4 = null; private JPanelClass c5 = null; private JPanelClass c6 = null; private JPanelClass c7 = null; private JPanelClass c8 = null; private JPanelClass c9 = null; private JPanelClass c10 = null; private JPanelClass[] cs = null; public Excel getExcel() { return excel; } public void setExcel(Excel excel) { this.excel = excel; } public Information getInformation() { return information; } public JPanelName getJpName() { return jpName; } public JPanelList getJpList() { return jpList; } public JPanelText getJpText() { return jpText; } public void createMenu() { newFile = new JMenu("����"); select = new JMenuItem("�������� �ҷ��1�"); help = new JMenu("����"); about = new JMenuItem("d��"); mb = new JMenuBar(); newFile.add(select); mb.add(newFile); help.add(about); mb.add(help); setJMenuBar(mb); } public void tabSetting() { jtab = new JTabbedPane(); //��ȭ�� ���� jpBefore = new JPanelBefore(information, this); jpName = new JPanelName(information, this); jpList = new JPanelList(information, this); jpText = new JPanelText(information, this); c1 = new JPanelClass(information, this, 1); c2 = new JPanelClass(information, this, 2); c3 = new JPanelClass(information, this, 3); c4 = new JPanelClass(information, this, 4); c5 = new JPanelClass(information, this, 5); c6 = new JPanelClass(information, this, 6); c7 = new JPanelClass(information, this, 7); c8 = new JPanelClass(information, this, 8); c9 = new JPanelClass(information, this, 9); c10 = new JPanelClass(information, this, 10); jtab.addTab("�����Է�", jpBefore); jtab.addTab("��� �Է�", jpName); jtab.addTab("���׸� �Է�", jpList); jtab.addTab("������ �����Է�", jpText); jtab.addTab("1��", c1); jtab.addTab("2��", c2); jtab.addTab("3��", c3); jtab.addTab("4��", c4); jtab.addTab("5��", c5); jtab.addTab("6��", c6); jtab.addTab("7��", c7); jtab.addTab("8��", c8); jtab.addTab("9��", c9); jtab.addTab("10��", c10); add(jtab); } public void dialogSetting() { //���� ���� - ���̾�α� dg = new JDialog(this, "Information", true); dg.setSize(400, 200); dg.setLocation(screen.width/2 - dg.getWidth()/2, screen.height/2 - dg.getHeight()/2); dg.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE); } aa public void fileDialogSetting() { //�ҷ��1� ���� - ���ϴ��̾�α� fdg = new FileDialog(this, "�������� �����ϱ�", FileDialog.LOAD); fdg.setDirectory("C:\\"); fdg.setFile("*.xls"); } public void actionEventStart() { //��ư�� �׼��̺�Ʈ �߰� // select.addActionListener(this); // open.addActionListener(this); about.addActionListener(this); } // public void loading(String pathName) { // } public void initComponent() { createMenu(); //�޴��ټ��� tabSetting(); //��ȭ�� ���� dialogSetting(); //���̾�α� ���� actionEventStart(); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == select) { //�������� ���� // fdg.setVisible(true); } else if (e.getSource() == about) { dg.setVisible(true); } } //���� public ViewFrame (String title) { super(title); screen = Toolkit.getDefaultToolkit().getScreenSize(); super.setSize(screen.width/2, screen.height/2); super.setLocation(screen.width/4, screen.height/4); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); information = new Information(); cs = new JPanelClass[] { c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 }; initComponent(); super.setVisible(true); } } public class Main { public static final int MAXPEOPLE= 40; public static void main(String[] args) { ViewFrame vf = new ViewFrame("������ ���wα׷� ver.1.0.0"); } }
package mini_excelVersion2_refactoring; public class Information { private String schoolName; private String isMiddle; private String grade; private int totalClass; private String subject; private int exams; private int[] ratings; private int ratingSum; public void setSchoolName(String schoolName) { this.schoolName = schoolName; } public String getSchoolName() { return schoolName; } public void setIsMiddle(String isMiddle) { this.isMiddle = isMiddle; } public String getIsMiddle() { return isMiddle; } public void setGrade(String grade) { this.grade = grade; } public String getGrade() { return grade; } public void setTotalClass(int totalClass) { this.totalClass = totalClass; } public int getTotalClass() { return totalClass; } public void setSubject(String subject) { this.subject = subject; } public String getSubject() { return subject; } public void setExams(int exams) { this.exams = exams; } public int getExams() { return exams; } public void setRatings(int[] ratings) { this.ratings = ratings; } public int[] getRatings() { return ratings; } public int getRating(int i) { return ratings[i]; } public void setRatingSum(int ratingSum) { this.ratingSum = ratingSum; } public int getRatingSum() { return ratingSum; } //���� public Information() { this.grade = "1"; this.totalClass = 1; this.exams = 1; this.ratings = new int[1]; this.ratingSum = 2; } }
package mini_excelVersion2_refactoring; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; public class Excel { private Information information; private String pathName; private File file; private FileOutputStream fos; private FileInputStream fis; private HSSFWorkbook wb; //�������Ϸ� �����Ҷ� ����ϴ� ��ũ�� private HSSFWorkbook wbIn; //�������� �ҷ��ö� ����ϴ� ��ũ�� private HSSFSheet sheet1; //����d�� �� ���׸� private HSSFSheet sheet2; //�̸�d�� private HSSFSheet sheet3; //������, ���δɷ� �� Ư����� private HSSFSheet sheet4; //1�� private HSSFSheet sheet5; private HSSFSheet sheet6; private HSSFSheet sheet7; private HSSFSheet sheet8; private HSSFSheet sheet9; private HSSFSheet sheet10; private HSSFSheet sheet11; private HSSFSheet sheet12; private HSSFSheet sheet13; private HSSFSheet[] sheets; private HSSFRow row = null; private HSSFCell cell = null; HSSFCellStyle csCenter; HSSFCellStyle csRight; HSSFCellStyle csLeft; HSSFCellStyle csWrap; public String getPathName() { return pathName; } public HSSFSheet[] getSheets() { return sheets; } public void excelBefore() { sheet1.setColumnWidth(0, 3000); for(int i = 0 ; i < 10 ; i++) { sheet1.setColumnWidth(i+1, 6000); } // row = sheet1.createRow(0); cell = row.createCell(0); cell.setCellValue(information.getSchoolName()); cell.setCellStyle(csRight); cell = row.createCell(1); cell.setCellValue(information.getIsMiddle()); cell.setCellStyle(csLeft); cell = row.createCell(2); cell.setCellValue(information.getGrade()); cell.setCellStyle(csRight); cell = row.createCell(3); cell.setCellValue("�г�"); cell.setCellStyle(csLeft); cell = row.createCell(4); cell.setCellValue("����"); cell.setCellStyle(csCenter); cell = row.createCell(5); cell.setCellValue(information.getSubject()); cell.setCellStyle(csCenter); row = sheet1.createRow(1); cell = row.createCell(0); cell.setCellValue("�� �ݼ�"); cell.setCellStyle(csCenter); cell = row.createCell(1); cell.setCellValue(information.getTotalClass()); cell.setCellStyle(csCenter); cell = row.createCell(2); cell.setCellValue("���׸� ��"); cell.setCellStyle(csCenter); cell = row.createCell(3); cell.setCellValue(information.getExams()); cell.setCellStyle(csCenter); row = sheet1.createRow(3); cell = row.createCell(0); cell.setCellValue("�� ��ȣ"); cell.setCellStyle(csCenter); for(int i = 0 ; i < information.getExams() ; i++) { cell = row.createCell(i+1); cell.setCellValue((i+1)+""); cell.setCellStyle(csCenter); } row = sheet1.createRow(4); cell = row.createCell(0); cell.setCellValue("��޼�"); cell.setCellStyle(csCenter); for(int i = 0 ; i < information.getExams() ; i++) { cell = row.createCell(i+1); cell.setCellValue(information.getRating(i)); cell.setCellStyle(csCenter); } row = sheet1.createRow(6); cell = row.createCell(0); cell.setCellValue("�� ��ȣ"); cell.setCellStyle(csCenter); cell = row.createCell(1); cell.setCellValue("�򰡿���"); cell.setCellStyle(csCenter); cell = row.createCell(2); cell.setCellValue("�򰡳���"); cell.setCellStyle(csCenter); cell = row.createCell(3); cell.setCellValue("���׸�"); cell.setCellStyle(csCenter); cell = row.createCell(4); cell.setCellValue("�򰡵���"); cell.setCellStyle(csCenter); for(int i = 0 ; i < information.getExams() ; i++) { row = sheet1.createRow(i+7); cell = row.createCell(0); cell.setCellValue((i+1)+""); cell.setCellStyle(csCenter); } } public void excelName() { sheet2.setColumnWidth(0, 2000); for(int i = 0 ; i < information.getTotalClass() ; i++) { sheet2.setColumnWidth(i+1, 3000); } // row = sheet2.createRow(0); cell = row.createCell(0); cell.setCellValue("��ȣ"); cell.setCellStyle(csCenter); for(int i = 0 ; i < information.getTotalClass() ; i++) { cell = row.createCell(i+1); cell.setCellValue((i+1)+"��"); cell.setCellStyle(csCenter); } for(int i = 0 ; i < Main.MAXPEOPLE; i++) { row = sheet2.createRow(i+1); cell = row.createCell(0); cell.setCellValue((i+1)+""); cell.setCellStyle(csCenter); for(int j = 0 ; j < information.getTotalClass() ; j++) { cell = row.createCell(j+1); cell.setCellValue(""); cell.setCellStyle(csCenter); } } } public void excelText() { sheet3.setColumnWidth(0, 3000); sheet3.setColumnWidth(1, 3000); sheet3.setColumnWidth(2, 30000); // row = sheet3.createRow(0); cell = row.createCell(0); cell.setCellValue("�򰡸�"); cell.setCellStyle(csCenter); cell = row.createCell(1); cell.setCellValue("������"); cell.setCellStyle(csCenter); cell = row.createCell(2); cell.setCellValue("���δɷ� �� Ư�����"); cell.setCellStyle(csCenter); int sum = 1; for(int i = 0 ; i < information.getExams() ; i++) { row = sheet3.createRow(sum); cell = row.createCell(0); cell.setCellValue("��"+(i+1)); cell.setCellStyle(csCenter); cell = row.createCell(1); cell.setCellValue("A"); cell.setCellStyle(csCenter); cell = row.createCell(2); cell.setCellStyle(csWrap); for(int j = 1 ; j < information.getRating(i) ; j++) { row = sheet3.createRow(sum+j); cell = row.createCell(1); cell.setCellValue((char)(65+j)+""); cell.setCellStyle(csCenter); } sum += information.getRating(i); } } public void excelEtc() { // sheet2 names ���� �ϼ� for(int i = 0 ; i < Main.MAXPEOPLE +1 ; i++) { row = sheet2.createRow(i); for(int j = 0 ; j < information.getTotalClass() + 1 ; j++) { cell = row.createCell(j); cell.setCellValue(information.getName(i, j)); cell.setCellStyle(csCenter); } } // sheet1 list d�� �ϼ� for(int i = 0 ; i < information.getExams() +1 ; i++) { row = sheet1.createRow(i+6); for(int j = 0 ; j < 5 ; j++) { cell = row.createCell(j); cell.setCellValue(information.getList(i, j)); cell.setCellStyle(csCenter); } } // sheet3 text ���� �ϼ� for(int i = 0 ; i < information.getRatingSum() +1 ; i++) { row = sheet3.createRow(i); for(int j = 0 ; j < 3 ; j++) { cell = row.createCell(j); cell.setCellValue(information.getRatingText(i, j)); cell.setCellStyle(csCenter); } } } public void excelClass(HSSFSheet sheet, int classNumber) { sheet.setColumnWidth(information.getExams()+2, 30000); String[][] tmp = information.getResult(classNumber); //42 * exams+3 for(int i = 0 ; i < Main.MAXPEOPLE+2 ; i++) { row = sheet.createRow(i); for(int j = 0 ; j < information.getExams()+3 ; j++) { cell = row.createCell(j); cell.setCellValue(tmp[i][j]); cell.setCellStyle(csCenter); if (j == information.getExams()+2) { cell.setCellStyle(csWrap); } } } } public String getExcel(int sheet, int i , int j) { try { fis = new FileInputStream(file); wbIn = new HSSFWorkbook(fis); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } HSSFSheet sh = wbIn.getSheetAt(sheet); HSSFRow rw = sh.getRow(i); HSSFCell cl = rw.getCell(j); if (cl == null) { return ""; } else if( cl.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) { return String.valueOf( cl.getNumericCellValue()); } else return cl.getStringCellValue(); } //�������� �� // ���� ���ϸ��� ������ ����Ǿ�;�� ����� ��. public void makeExcel() { // pathName��η� wb�� ����; ������ ����. try { pathName = information.getSchoolName() + information.getIsMiddle() + information.getGrade() +"�г�.xls"; file = new File(pathName); if (!file.exists()) file.createNewFile(); fos = new FileOutputStream(file); wb.write(fos); fos.close(); } catch(FileNotFoundException e) { } catch(IOException e) { } } //���� public Excel(Information information) { this.information = information; wb = new HSSFWorkbook(); sheet1 = wb.createSheet("����d�� �� ���׸�"); sheet2 = wb.createSheet("�̸�d��"); sheet3 = wb.createSheet("������, ���δɷ� �� Ư�����"); sheet4 = wb.createSheet("1��"); sheet5 = wb.createSheet("2��"); sheet6 = wb.createSheet("3��"); sheet7 = wb.createSheet("4��"); sheet8 = wb.createSheet("5��"); sheet9 = wb.createSheet("6��"); sheet10 = wb.createSheet("7��"); sheet11 = wb.createSheet("8��"); sheet12 = wb.createSheet("9��"); sheet13 = wb.createSheet("10��"); sheets =new HSSFSheet[10]; sheets[0] = sheet4; sheets[1] = sheet5; sheets[2] = sheet6; sheets[3] = sheet7; sheets[4] = sheet8; sheets[5] = sheet9; sheets[6] = sheet10; sheets[7] = sheet11; sheets[8] = sheet12; sheets[9] = sheet13; csCenter = wb.createCellStyle(); csRight = wb.createCellStyle(); csLeft = wb.createCellStyle(); csWrap = wb.createCellStyle(); csCenter.setAlignment(HSSFCellStyle.ALIGN_CENTER); csRight.setAlignment(HSSFCellStyle.ALIGN_RIGHT); csLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT); csWrap.setWrapText(true); //�ٹٲ� } }
package mini_excelVersion2_refactoring; import java.awt.BorderLayout; import java.awt.Choice; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; public class JPanelBefore extends JPanel implements ActionListener { private Information information; private ViewFrame vf; private JPanel pn1; private JPanel pn2; private JPanel pn1_1; private JPanel pn1_2; private JPanel pn1_3; private JPanel pn2_1; private JButton reset1; //�ʱ�ȭ private JButton save1; //���� private JButton reset2; //�ʱ�ȭ private JButton save2; //���� private JTextField schoolName; //�б��� �Է� private Choice isMiddle; //���б�/����б� ���� private Choice grade; //�г� ���� private Choice totalClass; //�� �ݼ� ���� private JTextField subject; //���� private Choice exams; //�� ���׸� �� (ex. �� �ܿ� ��) private JTable examsTable; private JScrollPane jspExams; public void setRatingsSum() { int sum = 0; for (int i = 0 ; i < information.getExams() ; i++) { sum += information.getRating(i); } information.setRatingSum(sum); } public void panel1Setting() { pn1_1.setLayout(new FlowLayout(FlowLayout.RIGHT)); pn1_1.add(reset1); pn1_1.add(save1); pn1_2.add(schoolName); pn1_2.add(isMiddle); pn1_2.add(grade); pn1_2.add(new JLabel("�г� ")); pn1_3.add(new JLabel("�� �ݼ� ")); pn1_3.add(totalClass); pn1_3.add(new JLabel(" ���� ")); pn1_3.add(subject); pn1_3.add(new JLabel(" ���׸� �� ")); pn1_3.add(exams); pn1.setLayout(new GridLayout(3, 1)); pn1.add(pn1_1); pn1.add(pn1_2); pn1.add(pn1_3); } public void panel2Setting() { pn2_1.setLayout(new FlowLayout(FlowLayout.RIGHT)); pn2_1.add(reset2); pn2_1.add(save2); examsTableSetting(); pn2.setLayout(new BorderLayout()); pn2.add(pn2_1, BorderLayout.NORTH); pn2.add(jspExams, BorderLayout.CENTER); JLabel warning = new JLabel("<html>���� ĭ �Է��� TabŰ�� ������ �Էµ� ���� ����˴ϴ�.<br>" + "�۾� ���� �����Է��� �����ư; �ٽ� ������ �۾���� �ʱ�ȭ�Ǵ� /���Ͻñ� �ٶ�ϴ�.</html>"); pn2.add(warning , BorderLayout.SOUTH); } public void examsTableSetting() { String[] header = new String[information.getExams()+1]; String[][] contents = new String[1][information.getExams()+1]; header[0] = "�򰡹�ȣ"; for(int i=1 ; i<information.getExams()+1 ; i++) { header[i] = i+""; } contents[0][0] = "���׸� ��� ��"; for(int i=1 ; i<information.getExams()+1 ; i++) { contents[0][i] = ""; } DefaultTableModel modelExams = new DefaultTableModel(contents, header); examsTable = new JTable(modelExams); examsTable.getTableHeader().setReorderingAllowed(false); //���̺� column �̵� ��� examsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //���� ��ũ�ѹ� �� DefaultTableCellRenderer alignCenter = new DefaultTableCellRenderer(); //���d�� ��d(����'��) alignCenter.setHorizontalAlignment(JLabel.CENTER); examsTable.getColumnModel().getColumn(0).setMinWidth(120); //0�� ũ�⸦ 1208�� examsTable.setRowHeight(30); // ��ü �� ���̸� 308�� for(int i = 0 ; i<information.getExams()+1 ; i++) { examsTable.getColumnModel().getColumn(i).setCellRenderer(alignCenter); } jspExams = new JScrollPane(examsTable); } public void actionEventStart() { //��ư�� �׼��̺�Ʈ �߰� reset1.addActionListener(this); save1.addActionListener(this); reset2.addActionListener(this); save2.addActionListener(this); } public void initComponent() { pn1 = new JPanel(); pn2 = new JPanel(); pn1_1 = new JPanel(); //��ư�� pn1_2 = new JPanel(); pn1_3 = new JPanel(); pn2_1 = new JPanel(); //��ư�� reset1 = new JButton("�ʱ�ȭ"); save1 = new JButton("����"); reset2 = new JButton("�ʱ�ȭ"); save2 = new JButton("����"); schoolName = new JTextField(10); isMiddle = new Choice(); grade = new Choice(); totalClass = new Choice(); subject = new JTextField(10); exams = new Choice(); isMiddle.add("���б�"); isMiddle.add("����б�"); for(int i = 0 ; i<3; i++) { //1~3 grade.add((i+1)+""); } for(int i = 0 ; i<10; i++) { //1~10 totalClass.add((i+1)+""); } for(int i = 0 ; i<20; i++) { //1~20 exams.add((i+1)+""); } panel1Setting(); panel2Setting(); setLayout(new GridLayout(2,1)); add(pn1); add(pn2); } public void initEvent() { actionEventStart(); //��ư�� �׼��̺�Ʈ �߰� } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == reset1) { schoolName.setText(""); isMiddle.select(0); grade.select(0); totalClass.select(0); subject.setText(""); exams.select(0); } else if (e.getSource() == save1 ) { //5 excel version vf.setExcel(new Excel(vf.getInformation())); //vf�� information����d���� ������ excel�⺻Ʋ; ����� vf�� excel ���� ����. vf.getExcel().excelBefore(); //vf�� excel ����� excejBefore() ���� - �⺻Ʋ �� �⺻d�� �Է� vf.getExcel().excelName(); //vf�� excel ����� excelName() ���� - �̸��Է� �⺻Ʋ �� vf.getExcel().excelText(); //vf�� excel ����� excelText() ���� - ���δɷ� �� Ư����� �⺻Ʋ �� vf.getExcel().makeExcel(); //vf�� excel ����� makeExcel() ���� - excel���� �� //1 red information.setSchoolName(schoolName.getText()); information.setIsMiddle(isMiddle.getSelectedItem()); information.setGrade(grade.getSelectedItem()); information.setTotalClass(Integer.parseInt(totalClass.getSelectedItem())); information.setSubject(subject.getText()); information.setExams(Integer.parseInt(exams.getSelectedItem())); //2 pn2.removeAll(); // �̰� �߿�!!! panel2Setting(); //3 vf.getJpName().removeAll(); vf.getJpName().namesTableSetting(); //4 vf.getJpList().removeAll(); vf.getJpList().listTableSetting(); vf.repaint(); } else if (e.getSource() == reset2 ) { for(int i = 0 ; i < information.getExams() ; i++) { examsTable.setValueAt("", 0, i+1); } } else if (e.getSource() == save2) { //1 blue int[] tmp = new int[information.getExams()]; try { for(int i = 0 ; i < information.getExams() ; i++) { tmp[i] = Integer.parseInt((String) examsTable.getValueAt(0, i+1)); } } catch (NumberFormatException e1) { JOptionPane.showMessageDialog(null, "�Է�; �Ϸ����� �ʾҰų� ���� �̿��� ��; �Է��Ͽ��4ϴ�."); return; } information.setRatings(tmp); //info��ü�� ratings �� ���� //2 setRatingsSum(); //info��ü�� ratingSum �� ����ؼ� ���� //3 vf.getJpText().removeAll(); //ratingSum ����Ʈ �� Text�г� ���� vf.getJpText().textTableSetting(); //4 for(int i = 0 ; i < information.getTotalClass(); i++) { vf.getClasses().get(i+1).removeAll(); vf.getClasses().get(i+1).classTableSetting(); } vf.repaint(); } } //���� public JPanelBefore (Information information, ViewFrame vf) { this.information = information; this.vf = vf; initComponent(); initEvent(); } }
package mini_excelVersion2_refactoring; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; public class JPanelClass extends JPanel implements ActionListener { // �� �г� (1~10�ݱ��� ��ü 10�� ��) private Information information; private ViewFrame vf; private int classNumber; private JLabel info; private JLabel warning; private JPanel pn1; private JButton renewal; //���� private JButton reset; //�ʱ�ȭ private JButton save; //���� private JButton saveInExcel; //������ ���� private JTable classTable; private JScrollPane jspClass; // public JTable getClassTable() { return classTable; } // public void classTableSetting() { String[] header = new String[information.getExams()+3]; String[][] contents = new String[Main.MAXPEOPLE + 1][information.getExams()+3]; header[0] = "��ȣ"; header[1] = "����"; for (int i = 0 ; i<information.getExams() ; i++) { header[i+2] = "�� " + (i+1); } header[information.getExams()+2] = ""; contents[0][0] = ""; contents[0][1] = ""; for(int i = 0 ; i<information.getExams() ; i++) { contents[0][i+2] = "A~" + (char)(information.getRating(i)+64); } for(int i = 0 ; i < Main.MAXPEOPLE ; i++) { contents[i+1][0] = (i+1)+""; } DefaultTableModel modelClass = new DefaultTableModel(contents, header); classTable = new JTable(modelClass); classTable.getTableHeader().setReorderingAllowed(false); //���̺� column �̵� ��� classTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //���� ��ũ�ѹ� �� DefaultTableCellRenderer alignCenter = new DefaultTableCellRenderer(); alignCenter.setHorizontalAlignment(JLabel.CENTER); //���d�� for(int i = 0 ; i<information.getExams()+3 ; i++) { classTable.getColumnModel().getColumn(i).setCellRenderer(alignCenter); //���d�� ��� } classTable.getColumnModel().getColumn(information.getExams()+2).setMinWidth(800); //��ũ�� classTable.setRowHeight(25); // ����� 25 jspClass = new JScrollPane(classTable); // info.setText(information.getGrade() + "�г� " + classNumber + "�� " +" ���δɷ� �� Ư����� "); warning.setText(" �� ������ ��' ���� a�� �Է����� ��8�� �ش� ���� Ư�����: �Էµ��� �ʽ4ϴ�."); pn1.setLayout(new FlowLayout(FlowLayout.LEFT)); pn1.add(info); pn1.add(renewal); pn1.add(reset); pn1.add(save); pn1.add(saveInExcel); pn1.add(warning); setLayout(new BorderLayout()); add(pn1, BorderLayout.NORTH); add(jspClass, BorderLayout.CENTER); } public void renewal() { for(int i = 0 ; i < Main.MAXPEOPLE ; i++) { //�л��ȣ i+1�� String totalResult = ""; for(int j = 0 ; j < information.getExams() ; j++) { //��(j+1) String tmp = (String)classTable.getValueAt(i+1, j+2); //��(j+1) ��� : A~ int range = information.getRating(j); //��(j+1)�� ��޼�(��') String result = ""; int sum = 0; for(int k = 0 ; k < range ; k++) { //�򰡵�� k=0 -> A, k=1 -> B, .. String pt1 = (char)(k+65)+""; //A~ String pt2 = (char)(k+97)+""; //a~ if (pt1.equals(tmp) || pt2.equals(tmp)){ //k�߿� 1���� ��=. //��ҹ��� �Ѵ� ���� for(int l = 0 ; l < j ; l++) { sum += information.getRating(l); } result = information.getRatingText()[sum+k+1][2]; } } totalResult += result+" "; } classTable.setValueAt(totalResult, i+1, information.getExams()+2); } } public void actionEventStart() { //��ư�� �׼��̺�Ʈ �߰� renewal.addActionListener(this); reset.addActionListener(this); save.addActionListener(this); saveInExcel.addActionListener(this); } public void initComponent() { pn1 = new JPanel(); renewal = new JButton("����"); reset = new JButton("�ʱ�ȭ"); save = new JButton("����"); saveInExcel = new JButton("������ ����"); info = new JLabel(); warning = new JLabel(); actionEventStart(); //��ư�� �׼��̺�Ʈ �߰� classTableSetting(); } public void initEvent() { } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == renewal) { renewal(); } else if (e.getSource() == reset) { // �̸� d���� �����ֵ��� ©��.!!! // ����Է¿��� �����ҷ��1� �ϸ� ��. removeAll(); classTableSetting(); } else if (e.getSource() == save ) { String[][] tmp = new String[42][information.getExams()+3]; tmp[0][0] = "��ȣ"; tmp[0][1] = "����"; for(int i = 0 ; i < information.getExams(); i++) { tmp[0][i+2] = "��"+(i+1); } tmp[0][information.getExams()+2] = "���δɷ� �� Ư�����"; for(int i = 0 ; i < Main.MAXPEOPLE+1 ; i++) { for(int j = 0 ; j < information.getExams()+3 ; j++) { tmp[i+1][j] = (String) classTable.getValueAt(i, j); } } information.setResult(classNumber-1, tmp); } else if(e.getSource() == saveInExcel) { HSSFSheet tmpSheet = vf.getExcel().getSheets()[classNumber-1]; //classNumber�� �ش��ϴ� ���� sheet vf.getExcel().excelEtc(); vf.getExcel().excelClass(tmpSheet, classNumber); vf.getExcel().makeExcel(); //vf�� excel ����� makeExcel() ���� - excel���� �� } } //���� public JPanelClass (Information information, ViewFrame vf, int classNumber) { this.information = information; this.vf = vf; this.classNumber = classNumber; initComponent(); initEvent(); } }
Editor Settings
Theme
Key bindings
Full width
Lines