Friday, April 13, 2007

Accounts Entry

import java.text.*;
import javax.swing.text.MaskFormatter;
import java.text.Format.*;
import java.text.ParseException;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.*;
import java.util.*;
import java.util.Calendar;
import java.text.DateFormatSymbols;
import javax.swing.DefaultCellEditor;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import java.text.*;
import javax.swing.text.MaskFormatter;
import java.text.Format.*;
import javax.swing.table.AbstractTableModel;


//CLASS OF frame 2 FOR STUDENT FILE

class AccountsEntry extends JFrame{
//ds
String output="";
int row=200, col=5;
private JLabel pic2, label, label1, label2, label3, label4,label5,label6,label7;
private JTextField field1, field2, field3, field4, field5, field6, field7;
private JTable inventTable;
private JScrollPane inventScroll1;
JComboBox combo1, combo2, combo3;
private String gender[] = {"Male","Female"};
private String semester[] = {"First", "Second", "Summer"};
private String status[] = {"New", "Old/Active", "Returnee", "Transferee"};
private JRadioButton student,staff;
private ButtonGroup radioGroup;

JButton buttonadd;
JButton buttonsave;
JButton buttonsearch;
JButton buttonprint;
JButton buttonclose;
JButton buttondelete;
JRadioButton buttonstudent;
JRadioButton buttonstaff;
ButtonGroup radiogroup;


public AccountsEntry()
{
setTitle("ACCOUNTS FORM");
Container pane = getContentPane();
JTextArea textarea;

pane.setBackground(Color.black);
pane.setLayout(null);
Font font = new Font("Teletype",Font.PLAIN,18);


JLabel label = new JLabel("CJC Center for Instructional and Mimeographing Services"+"\n"+" INVENTORY SYSTEM",JLabel.CENTER);
label.setFont(font);
label.setBounds(0,0,790,60);
label.setForeground(Color.yellow);
label.setBackground(Color.blue);
label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
pane.add(label,BorderLayout.CENTER);


//for pictures or logo
Icon logo = new ImageIcon("logo2.gif");
pic2 = new JLabel(logo);
pic2.setBounds(0,0,60,60);
pane.add(pic2);

//SET DATE HERE
//textarea = new JTextArea();
GregorianCalendar today = new GregorianCalendar();

String[]weekdays = new DateFormatSymbols().getWeekdays();
String[]months = new DateFormatSymbols().getMonths();

output+=""+weekdays[today.get(today.DAY_OF_WEEK)];
output+=", "+(today.get(today.DATE))+" ";
output+=months[today.get(today.MONTH)]+"";
output+=today.get(today.YEAR)+"\n";

//TABLE HERE
/*******JTable inventTable = new JTable(row,col);
inventTable.setGridColor(Color.gray);

JScrollPane inventScroll = new JScrollPane(inventTable);
inventScroll.setBounds(30,280,650,150);
pane.add(inventScroll);

****************/

//LABELS HERE
label = new JLabel("A C C O U N T S E N T R Y");
label.setBounds(250,80,450,50);
label.setFont(new Font("Broadway BT",Font.BOLD,20));
label.setForeground(Color.red);
label.setBackground(Color.blue);
pane.add(label);


label1 = new JLabel("Date:");
label1.setBounds(555,150,200,20);
label1.setFont(new Font("Tahoma",Font.PLAIN,14));
label1.setForeground(Color.white);
pane.add(label1);
field1 = new JTextField();
field1.setBounds(592,150,160,20);
field1.setText(output);
field1.setForeground(Color.blue);
pane.add(field1);

label2 = new JLabel("ID Number:");
label2.setBounds(10,150,100,20);
label2.setFont(new Font("Tahoma",Font.PLAIN,14));
label2.setForeground(Color.white);
pane.add(label2);

try{
MaskFormatter mf1 = new MaskFormatter("####-####-#");
JFormattedTextField field2 = new JFormattedTextField(mf1);
field2.setBounds(85,150,80,20);
//field2.setText("");
field2.setForeground(Color.blue);
pane.add(field2);
}
catch(ParseException pe){
}
label3 = new JLabel("Name:");
label3.setBounds(10,200,250,20);
label3.setFont(new Font("Tahoma",Font.PLAIN,14));
label3.setForeground(Color.white);
pane.add(label3);
field3 = new JTextField();
field3.setBounds(85,200,250,20);
field3.setText("");
field3.setFont(new Font("Tahoma",Font.BOLD,14));
field3.setForeground(Color.blue);
pane.add(field3);

label4 = new JLabel("Status:");
label4.setBounds(190,150,105,20);
label4.setFont(new Font("Tahoma",Font.PLAIN,14));
label4.setForeground(Color.white);
pane.add(label4);

combo3 = new JComboBox(status);
combo3.setBounds(235,150,100,20);
combo3.setForeground(Color.blue);
pane.add(combo3);

label5 = new JLabel("Course/Year:");
label5.setBounds(585,200,100,20);
label5.setFont(new Font("Tahoma",Font.PLAIN,14));
label5.setForeground(Color.white);
pane.add(label5);

try{
MaskFormatter mf2 = new MaskFormatter("****-#");
JFormattedTextField field5 = new JFormattedTextField(mf2);
field5.setBounds(670,200,80,20);
//field5.setText("");
field5.setForeground(Color.blue);
pane.add(field5);
}
catch(ParseException pe){
}

label6 = new JLabel("Semester:");
label6.setBounds(360,150,100,20);
label6.setFont(new Font("Tahoma",Font.PLAIN,14));
label6.setForeground(Color.white);
pane.add(label6);

combo1 = new JComboBox(semester);
combo1.setBounds(425,150,100,20);
combo1.setForeground(Color.blue);
pane.add(combo1);

label7 = new JLabel("Gender:");
label7.setBounds(375,200,100,20);
label7.setFont(new Font("Tahoma",Font.PLAIN,14));
label7.setForeground(Color.white);
pane.add(label7);

combo2 = new JComboBox(gender);
combo2.setBounds(425,200,100,20);
combo2.setForeground(Color.blue);
pane.add(combo2);

MyTable tbl = new MyTable();
inventTable=new JTable(tbl);
inventScroll1=new JScrollPane(inventTable);
inventScroll1.setBounds(10,280,500,100);
pane.add(inventScroll1);


JPanel bottompanel=new JPanel();
bottompanel.setBackground(Color.white);




//dimension size of button
Dimension size=new Dimension(50,30);
//bevel JLabel label1 = newbutton
Border edge=BorderFactory.createRaisedBevelBorder();

//declare bottons


JPanel panels=new JPanel();
panels.setBounds(30,235,200,40);
panels.setBorder(new CompoundBorder(BorderFactory.createLineBorder(Color.black,1),
BorderFactory.createBevelBorder(BevelBorder.LOWERED)));
buttonstudent=new JRadioButton("Student");
buttonstaff=new JRadioButton("Staff");
radiogroup=new ButtonGroup();
radiogroup.add(buttonstudent);
radiogroup.add(buttonstaff);
panels.add(buttonstudent);
panels.add(buttonstaff);
pane.add(panels);




buttonadd = new JButton("ADD");
buttonadd.setBounds(50,520,80,30);
buttonadd.setPreferredSize(size);
buttonadd.setBorder(edge);
buttonadd.setToolTipText("click this button to add file.");
buttonadd.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
buttonadd.setFont(new Font("Arial",Font.BOLD,14));
buttonadd.setBackground(new Color(10,250,210));
buttonadd.setForeground(new Color(0,5,255));
buttonadd.setMnemonic('A');
bottompanel.add(buttonadd);

buttonsave = new JButton("SAVE");
buttonsave.setPreferredSize(size);
buttonsave.setBorder(edge);
buttonsave.setToolTipText("it saves the files");
buttonsave.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
buttonsave.setFont(new Font("Arial",Font.BOLD,14));
buttonsave.setForeground(new Color(0,5,255));
buttonsave.setBackground(new Color(10,250,210));
buttonsave.setBounds(150,520,80,30);
buttonsave.setMnemonic('S');
bottompanel.add(buttonsave);

buttonprint = new JButton("PRINT");
buttonprint.setBounds(250,520,80,30);
buttonprint.setPreferredSize(size);
buttonprint.setBorder(edge);
buttonprint.setToolTipText("it gives you a hard copy");
buttonprint.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
buttonprint.setFont(new Font("Arial",Font.BOLD,14));
buttonprint.setForeground(new Color(0,5,255));
buttonprint.setBackground(new Color(10,250,210));
buttonprint.setMnemonic('P');
bottompanel.add(buttonprint);

buttonsearch = new JButton("SEARCH");
buttonsearch.setBounds(350,520,80,30);
buttonsearch.setPreferredSize(size);
buttonsearch.setBorder(edge);
buttonsearch.setToolTipText("click this button to find");
buttonsearch.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
buttonsearch.setFont(new Font("Arial",Font.BOLD,14));
buttonsearch.setForeground(new Color(0,5,255));
buttonsearch.setBackground(new Color(10,250,210));
buttonsearch.setMnemonic('R');
bottompanel.add(buttonsearch);

buttondelete = new JButton("DELETE");
buttondelete.setBounds(450,520,80,30);
buttondelete.setPreferredSize(size);
buttondelete.setBorder(edge);
buttondelete.setToolTipText("Click this button to erase the file");
buttondelete.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
buttondelete.setFont(new Font("Arial",Font.BOLD,14));
buttondelete.setForeground(new Color(0,5,255));
buttondelete.setBackground(new Color(10,250,210));
buttondelete.setMnemonic('D');
bottompanel.add(buttondelete);


buttonclose = new JButton("CLOSE");
buttonclose.setBounds(550,520,80,30);
buttonclose.setPreferredSize(size);
buttonclose.setBorder(edge);
buttonclose.setToolTipText("Click this button to terminate the frame");
buttonclose.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
buttonclose.setFont(new Font("Arial",Font.BOLD,14));
buttonclose.setForeground(new Color(0,5,255));
buttonclose.setBackground(new Color(10,250,210));
buttonclose.setMnemonic('C');
bottompanel.add(buttonclose);

//pane.add(bottompanel);
pane.add(buttonsearch);
pane.add(buttonadd);
pane.add(buttonprint);
pane.add(buttonsave);
pane.add(buttonclose);
pane.add(buttondelete);

//pane.add(buttonstudent);
//pane.add(buttonstaff);

buttonclose.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
setVisible(false);
}
}
);
}
}
//TABLE HEREEEEEEEEEEEEEEEEEEEEEE

class MyTable extends AbstractTableModel {
final String[] columndata={"DATE","CHARGE","CREDIT","BALANCE"};
final Object[][] data = new Object[14][6];


public Object getValueAt(int row, int col) {
return data[row][col];
}

public int getColumnCount() {
return columndata.length;
}

public int getRowCount() {
return data.length;
}

public String getColumnName(int col) {
return columndata[col];
}


/*
* Don't need to implement this method unless your table's
* editable.
*/

public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
if (col < 0) {
return false;
} else {
return true;
}
}

public void setValueAt(Object value, int row, int col) {

data[row][col] = value;
fireTableCellUpdated(row, col);
System.out.println(data[row][col]);
}

}

No comments: