|
-
March 28th, 2007, 03:02 PM
#1
problems with Java code
I have an error that says "Illegal start of expression" for the line
public void actionPerformed(ActionEvent e) (line 185)
for the class named ScheduleFrame.java
and another error that says that ; is expected (line 310) , but i do not know exactly where do i put the ;
This is the whole code for ScheduleFrame.java
/**
*Creation of a Graphical User Interface with many functions.
*
* @author (Aigini)
* @version (a version number or a date)
*/
import javax.swing.*;
import static javax.swing.JOptionPane.*;
import java.awt.*;
import java.awt.event.*;
/**
* Creating class ScheduleFrame which has labels, text fields, text areas,
* buttons, panels, containers, scroll panes and combo boxes.
*/
public class ScheduleFrame extends JFrame implements ActionListener {
/**initializing J-type variables*/
private JLabel lbnum, lbc_code, lbdate, lbtime, lbdur, lbroomnum;
private JTextField tfnum,tfc_code, tfroomnum,tfdel,tfedit;
private JTextArea tashow;
private JButton badd, bsearch, bsort, bdelete, bshow,bedit;
private JPanel pan1, pan2, pan3, pan4, pan5, pan6;
private Container c;
private JScrollPane scroll;
private Schedule u;
private Exam ex[];
private int count;
private JComboBox cbday, cbmonth, cbyear;
private JComboBox cbsec, cbmin, cbhour;
private JComboBox cbsec1, cbmin1, cbhour1;
/**constructing Schedule Frame*/
public ScheduleFrame() {
super("Exam Scheduler");
u = new Schedule();
c = getContentPane();
/**constructing labels*/
lbnum = new JLabel("Number : ");
lbc_code = new JLabel(" Course code : ");
lbdate = new JLabel(" Date : ");
lbtime = new JLabel(" Time : ");
lbdur = new JLabel(" Duration : ");
lbroomnum = new JLabel(" Room Number : ");
/**constructing text fields*/
tfnum = new JTextField();
tfc_code = new JTextField();
tfroomnum = new JTextField();
/**constructing text area*/
tashow = new JTextArea();
tashow.setSize(500, 300);
scroll = new JScrollPane(tashow);
/**constructing buttons*/
badd = new JButton("Add");
bsearch = new JButton("Search");
bsort = new JButton("Sort");
bdelete = new JButton("Delete");
bshow = new JButton("Show");
bedit = new JButton("Edit");
/**construct JCombo Boxes*/
cbday = new JComboBox();
cbday.addItem("Day");
for (int k = 1; k < 32; k++) {
cbday.addItem(new Integer(k));
}
cbmonth = new JComboBox();
cbmonth.addItem("Month");
for (int i = 1; i < 13; i++) {
cbmonth.addItem(new Integer(i));
}
cbyear = new JComboBox();
cbyear.addItem("Year");
for (int n = 2007 ; n <3000; n++) {
cbyear.addItem(new Integer(n));
}
cbsec = new JComboBox();
cbsec.addItem("Second");
for (int k = 1; k < 61; k++) {
cbsec.addItem(new Integer(k));
}
cbmin = new JComboBox();
cbmin.addItem("Minute");
for (int i = 1; i < 61; i++) {
cbmin.addItem(new Integer(i));
}
cbhour = new JComboBox();
cbhour.addItem("Hour");
for (int n = 1; n < 25; n++) {
cbhour.addItem(new Integer(n));
cbsec1 = new JComboBox();
cbsec1.addItem("Second");
for (int k = 1; k < 61; k++) {
cbsec1.addItem(new Integer(k));
}
cbmin1 = new JComboBox();
cbmin1.addItem("Minute");
for (int i = 1; i < 61; i++) {
cbmin1.addItem(new Integer(i));
}
cbhour1 = new JComboBox();
cbhour1.addItem("Hour");
for (int n = 1; n < 25; n++) {
cbhour1.addItem(new Integer(n));
}
/**attaching actionListeners*/
badd.addActionListener(this);
bsearch.addActionListener(this);
bsort.addActionListener(this);
bdelete.addActionListener(this);
bshow.addActionListener(this);
bedit.addActionListener(this);
/**construct panels*/
pan1 = new JPanel();
pan2 = new JPanel();
pan3 = new JPanel();
pan4 = new JPanel();
pan5 = new JPanel();
pan6 = new JPanel();
/**assign layouts for panels*/
pan1.setLayout(new GridLayout(2, 2));
pan1.add(lbc_code); pan1.add(tfc_code);
pan1.add(lbroomnum); pan1.add(tfroomnum);
pan2.setLayout(new GridLayout(1, 5));
pan2.add(badd); pan2.add(bsearch); pan2.add(bsort);
pan2.add(bdelete); pan2.add(bshow);pan2.add(bedit);
pan2.setSize(500, 100);
pan3.setLayout(new GridLayout(4, 1));
pan3.add(pan1);
pan3.add(pan2);
pan3.add(pan4);
pan3.add(pan5);
pan3.add(pan6);
pan4.setLayout(new GridLayout(1, 4));
pan4.add(lbdate); pan4.add(cbday); pan4.add(cbmonth);
pan4.add(cbyear);
pan5.setLayout(new GridLayout(1, 4));
pan5.add(lbtime);
pan5.add(cbsec);pan5.add(cbmin);pan5.add(cbhour);
pan6.setLayout(new GridLayout(1,2));
pan6.add(lbdur);
pan6.add(cbsec1);pan6.add(cbmin1);pan6.add(cbhour1);
c.add(pan3, BorderLayout.NORTH);
c.add(scroll, BorderLayout.CENTER);
setSize(500, 500);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
/**making the buttons function
* @param badd = add button to add data into the file
* @param bsearch = search button to search for data in the file
* @param bshow = show button that will display all records once clicked
* @param bsort = sort button that will sort all the data displayed once clicked
* @param bedit = edit button that will edit details once clicked
* @param bdelete = delete button that will delete data once clicked
*/
public void actionPerformed(ActionEvent e) {
Object s = e.getSource();
if (s == badd) {
if (tfc_code.getText().trim() == "" || tfroomnum.getText().trim() == "") {
showMessageDialog(null, "Text Fields cannot leave blank!");
}
else {
int num = Integer.parseInt(tfnum.getText());
String c_code = tfc_code.getText();
String roomnum = tfroomnum.getText();
int day = (Integer)cbday.getSelectedItem();
int month = (Integer)cbmonth.getSelectedItem();
int year = (Integer)cbyear.getSelectedItem();
int sec = (Integer)cbsec.getSelectedItem();
int min = (Integer)cbmin.getSelectedItem();
int hour = (Integer)cbhour.getSelectedItem();
int sec1 = (Integer)cbsec1.getSelectedItem();
int min1 = (Integer)cbmin1.getSelectedItem();
int hour1 = (Integer)cbhour1.getSelectedItem();
Date date = new Date(day, month, year);
Time time = new Time(hour, min, sec);
Time dur = new Time(hour1, min1, sec1);
u.createRecord(num,c_code, date, time, dur, roomnum);
tfc_code.setText("");
tfroomnum.setText("");
cbday.setSelectedItem("Day");
cbmonth.setSelectedItem("Month");
cbyear.setSelectedItem("Year");
cbsec.setSelectedItem("Second");
cbmin.setSelectedItem("Minute");
cbhour.setSelectedItem("Hour");
cbsec1.setSelectedItem("Second");
cbmin1.setSelectedItem("Minute");
cbhour1.setSelectedItem("Hour");
}
}
else if (s == bshow) {
String show = u.readRecord();
tashow.setText(show);
}
else if (s == bsort) {
tashow.setText("");
String show = "Before sorted : \n" + u.readRecord();
u.sortDate();
show += "\nAfter sorted : \n" + u.readRecord();
tashow.setText(show);
}
else if (s == bsearch){
int day = (Integer)cbday.getSelectedItem();
int month = (Integer)cbmonth.getSelectedItem();
int year = (Integer)cbyear.getSelectedItem();
Date d = new Date(day,month,year);
String show = u.searchDate(d);
tashow.setText(show);
}
else if (s == bedit) {
tashow.setText("");
String show = "Before editing : \n" + u.readRecord();
int copy = 1;
for(int x = 0; x < count; x++)
show += x + " \t " + " \t " + ex[x].getCourse_code() + "\n";
/**ask user for edit selection*/
int edit = Integer.parseInt(tfedit.getText());
String c_code= tfc_code.getText();
String roomnum = tfroomnum.getText();
int day = (Integer)cbday.getSelectedItem();
int month = (Integer)cbmonth.getSelectedItem();
int year = (Integer)cbyear.getSelectedItem();
int sec = (Integer)cbsec.getSelectedItem();
int min = (Integer)cbmin.getSelectedItem();
int hour = (Integer)cbhour.getSelectedItem();
int sec1 = (Integer)cbsec1.getSelectedItem();
int min1 = (Integer)cbmin1.getSelectedItem();
int hour1 = (Integer)cbhour1.getSelectedItem();
Date d = new Date(day, month, year);
Time t = new Time(hour, min, sec);
Time dur = new Time(hour1, min1, sec1);
u.editRecord(edit,c_code,d,t,dur,roomnum);
show += "\nAfter editing : \n" + u.readRecord();
tashow.setText(show);
}
else if (s==bdelete){
tashow.setText("");
int del = Integer.parseInt(tfdel.getText());
String show = "Before deleting : \n" + u.readRecord();
u.deleteRecord(del);
show += "\nAfter deleting : \n" + u.readRecord();
tashow.setText(show);
}
}
public static void main(String args[]) {
ScheduleFrame h = new ScheduleFrame();
}
}
}
-
March 28th, 2007, 03:33 PM
#2
Re: problems with Java code
You seem to have a missing closing bracket after your ScheduleFrame constructor and before your actionPerformed() method.
It's good practice to break really long methods (like your ScheduleFrame constructor and your actionPerformed() method) into smaller methods. Not only is this good design (you can put common code into a method and call it from different locations, thus avoiding copying code, thus avoiding errors where you change your code in one place but forget to make a corresponding change in the other place), but also keeping the opening and closign brackets of a function on one screen helps to avoid problems like this...
Old Unix programmers never die, they just mv to /dev/null
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|