I'm doin my semester project and need to be hand-in by the 22 April..
So i seriously need help ugently..
I'm doin a Calendaer Planner application whereby user have to enter the Year & select the Month from drop-down list and follows by clicking on the New Calendar button.. doin so, the no. of days would then appear in a JList.. ( As u know, different months, have different no. of days ) therefore i'm not too sure if what i did is correct becos it can't be compile..
The Errors is ~
D: AppointmentPage.java:121: cannot resolve symbol
symbol : constructor JList (int[])
location: class javax.swing.JList
Daylist = new JList(noOfDays);
^
I putting up my source code.. Please help me.. Thanks
alot..
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import javax.swing.JList;
class AppointmentPage extends JFrame implements ActionListener {
private static final int FRAME_WIDTH = 420;
private static final int FRAME_HEIGHT = 470;
private static final int FRAME_X_ORIGIN = 280;
private static final int FRAME_Y_ORIGIN = 140;
private static final int BUTTON_WIDTH = 70;
private static final int BUTTON_HEIGHT = 30;
private static final int FEBRUARY = 1; // special month during leap year
private JButton addButton;
private JButton editButton;
private JButton printButton;
private JButton backButton;
private JButton mainButton;
private JButton CalButton;
private JLabel image ;
private JTextField dayInput ;
private JTextField timeInput ;
private JTextField yearInput;
private JTextArea appInput ;
// introduce list box
private JList Daylist;
private JScrollPane scrollPaneDaylist;
public static void main (
String[] args){
AppointmentPage frame = new AppointmentPage();
frame.setVisible(true);
}
public AppointmentPage (){
Container contentPane = getContentPane ();
// set the frame properties
setSize (FRAME_WIDTH, FRAME_HEIGHT);
setResizable (false);
setTitle ("View Appointment");
setLocation (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
// set the content pane properties
contentPane.setLayout (null);
contentPane.setBackground (Color.pink);
String Months[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int DaysInMonth[] = {31, 28, 31, 30, // January, February, March, April
31, 30, 31, 31, // May, June, July, August
30, 31, 30, 31}; // September, October, November, December
//Date object to get current month & year
Date now = new Date();
// Month & Year entered by user
int userMonth;
int userYear;
int numDays;
String dayStr; //number of days in month
// Month & Year to current values
userMonth = now.getMonth();
userYear = now.getYear() + 1900;
// Add images
image = new JLabel (new ImageIcon("viewApp.jpg"));
image.setBounds (10,20,390,50);
contentPane.add (image);
//Add Year textbox
yearInput = new JTextField ("1996",5);
yearInput.setBounds (70,100,50,20);
yearInput.setText(String.valueOf(userYear));
contentPane.add (yearInput);
// Add ComboBox to get month from user, add months, set default to now
Choice monthChoice = new Choice();
monthChoice.setBounds (147,100,90,20);
for(int i = 0; i < 12; i++)
monthChoice.addItem(Months[i]);
monthChoice.select(userMonth);
contentPane.add (monthChoice);
// Add Calbutton Button
CalButton = new JButton ("New Calendar");
CalButton.setBounds (260,100,120,BUTTON_HEIGHT);
contentPane.add (CalButton);
// Add Daylist
int[] noOfDays = {0,1,2,3};
Daylist = new JList(noOfDays);
Daylist.setBounds (70,150,80,100);
contentPane.add(Daylist);
// Add scroll bars to the list
scrollPaneDaylist = new JScrollPane (Daylist);
scrollPaneDaylist.setBounds (70,150,50,180);
contentPane.add (scrollPaneDaylist);
if (Months[userMonth] == "JANUARY" || Months[userMonth] == "MARCH" || Months[userMonth] == "MAY" || Months[userMonth] == "JULY" || Months[userMonth] == "AUGUST" || Months[userMonth] == "OCTOBER" || Months[userMonth] == "DECEMBER") {
noOfDays[0] = 31;
for (noOfDays[0] = 0; noOfDays[0] <= 31; noOfDays[0]++) {
System.out.println("1" + "2" + "3" + "4" + "5" + "6" + "7" + "8" + "9" + "10" + "11" + "12" + "13" + "14" + "15" + "16" + "17" + "18" + "19" + "20" + "21" + "22" + "23" + "24" + "25" + "26" + "27" + "28" + "29" + "30" + "31");
}
/*else if (Months[userMonth] == "APRIL" || Months[userMonth] == "JUNE" || Months[userMonth] == "SEPTEMBER" || Months[userMonth] == "NOVEMBER") {
for (noOfDays[0] = 0; noOfDays[0] <= 30; noOfDays[0]++) {
System.out.println("1" + "2" + "3" + "4" + "5" + "6" + "7" + "8" + "9" + "10" + "11" + "12" + "13" + "14" + "15" + "16" + "17" + "18" + "19" + "20" + "21" + "22" + "23" + "24" + "25" + "26" + "27" + "28" + "29" + "30");
}
}
else {
// Get number of days in months, adding 1 if Frebruary of leap year
noOfDays = DaysInMonth[userMonth] +
((IsLeapYear(userYear) && (userMonth == FEBRUARY))? 1:0);
for (noOfDays[0] = 0; noOfDays[0] <= 29; noOfDays[0]++) {
System.out.println("1" + "2" + "3" + "4" + "5" + "6" + "7" + "8" + "9" + "10" + "11" + "12" + "13" + "14" + "15" + "16" + "17" + "18" + "19" + "20" + "21" + "22" + "23" + "24" + "25" + "26" + "27" + "28");
}
}
*/
}
// Add 3 textfield
dayInput = new JTextField (" ");
dayInput.setBounds (147,160,130,20);
contentPane.add (dayInput);
timeInput = new JTextField (" ");
timeInput.setBounds (147,195,80,20);
contentPane.add (timeInput);
appInput = new JTextArea (" ");
appInput.setBounds (147,235,200,80);
contentPane.add (appInput);
// create and place 5 buttons on the frame's content pane
addButton = new JButton ("Add New");
addButton.setBounds (47,360, 100, BUTTON_HEIGHT);
contentPane.add (addButton);
editButton = new JButton ("Edit");
editButton.setBounds (183,360, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add (editButton);
printButton = new JButton ("Print");
printButton.setBounds (293,360, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add (printButton);
backButton = new JButton ("Back");
backButton.setBounds (131,400, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add (backButton);
mainButton = new JButton ("Main");
mainButton.setBounds (238,400, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add (mainButton);
// register this frame as an action listener of the 5 buttons
addButton.addActionListener (this);
editButton.addActionListener (this);
printButton.addActionListener (this);
backButton.addActionListener (this);
mainButton.addActionListener (this);
}
public void setDayInput(String dayInput,boolean editable) {
this.dayInput.setText(dayInput);
this.dayInput.setEditable(editable);
}
public String getDayInput() {
return dayInput.getText();
}
public void setYearInput(String yearInput,boolean editable) {
this.yearInput.setText(yearInput);
this.yearInput.setEditable(editable);
}
public String getYearInput() {
return yearInput.getText();
}
public void setTimeInput(String timeInput,boolean editable) {
this.timeInput.setText(timeInput);
this.timeInput.setEditable(editable);
}
public String getTimeInput() {
return timeInput.getText();
}
public void setAppInput(String appInput,boolean editable) {
this.appInput.setText(appInput);
this.appInput.setEditable(editable);
}
public String getAppInput() {
return appInput.getText();
}
public boolean action(Event e, Object o) { // Update month & year globals, paint when user clicks button
int userMonth;
int userYear;
int userYearInt;
Choice monthChoice = new Choice();
if (e.target instanceof Button) {
if ("New Calendar".equals((String)o)) {
// Get month from combo box (Choice control).
userMonth = monthChoice.getSelectedIndex();
// Get year from TextField, update userYear only if year ok.
userYearInt = Integer.parseInt(yearInput.getText(), 10);
if (userYearInt > 1581)
userYear = userYearInt;
return true;
}
}
return false;
}
boolean IsLeapYear(int year) { // determine if given year is a leap year
// if multiple of 100, leap year if multiple of 400
if((year % 100)==0) return ((year % 400)==0);
// otherwise leap year if multiple of 4
return ((year % 4)==0);
}
int CalcLeapYears(int year) { // calculate numbers of leap years since 1582
int leapYears; // number of leap years to return
int hundreds; // number of years multiple of a hundred
int fourHundreds; // number of years multiple of four hundred
// Start at 1582, when modern calendar starts.
if (year < 1582) return (-1);
// Calculate number of years in interval that are a multiple of 4.
leapYears = (year - 1581) / 4;
//Calculate number of years in interval that are a multiple of 100;
//subtract, since they are not leap years.
hundreds = (year - 1501) / 100;
leapYears -= hundreds;
// Calculate number of years in interval that are a multiple of 400;
//add back in, since they are still leap years.
fourHundreds = (year - 1201) / 400;
leapYears += fourHundreds;
return (leapYears);
}
// actionPerformed is invoked when a Button is clicked
public void actionPerformed(ActionEvent e) {
// see which button was clicked
if(e.getSource() == addButton){
enter();
}
if(e.getSource() == editButton){
edit();
}
if(e.getSource() == backButton){
appointment();
}
/*if(e.getSource() == printButton){
print();
}
if(e.getSource() == mainButton){
main();
} */
}
private void enter(){
EnterNew enterFrame = new EnterNew();
enterFrame.setSize(420,470);
enterFrame.setTitle("Appointment Entry");
enterFrame.setVisible(true);
this.setVisible(false);
}
private void edit(){
EditAppointment editFrame = new EditAppointment();
editFrame.setSize(420,470);
editFrame.setTitle("Edit Appointment");
editFrame.setVisible(true);
this.setVisible(false);
}
/*private void print(){
Print printFrame = new Print();
printFrame.setSize(420,470);
printFrame.setTitle("Printing In Process");
printFrame.setVisible(true);
this.setVisible(false);
}*/
private void appointment(){
Appointment appointmentFrame = new Appointment();
appointmentFrame.setSize(420,470);
appointmentFrame.setTitle("Appointment");
appointmentFrame.setVisible(true);
this.setVisible(false);
/*private void main(){
Main mainFrame = new Main();
mainFrame.setSize(420,470);
mainFrame.setTitle("Appointment");
mainFrame.setVisible(true);
this.setVisible(false);
*/
// register 'Exit upon closing' as a default close operation
setDefaultCloseOperation (EXIT_ON_CLOSE);
}
public void actionPerform (ActionEvent event){
if (event.getSource () instanceof JButton){
JButton clickedButton = (JButton) event.getSource();
String buttonText = clickedButton.getText();
setTitle ("You clicked " + buttonText);
} else { // the event source is inputLine
//setTitle ("You entered '" + date.getText() + "'");
}
}
}