17. december 2002 - 09:41
Der er
2 kommentarer
Er der virkelig ingen...........................
der er dygtige nok til at løse mit problem?? Det er blevet postet før, men nu sker det så igen, i overdreven desperation. Som sagt er jeg ved at lave en slags kalender, hvor man skal kunne booke tider ved at markere et felt i et JTable og derefter gemme tiden i feltet ved at trykke på en knap.
Jeg har tidspunkter på dagen ned ad y-aksen og datoer hen ad x-aksen. Jeg har lavet det sådan, at datoen ændrer sig således, at det altid er dags dato, der står som første dato over første kolonne. Man kan bestille en uge frem, og de resterende datoer rettes ind efter den første....altså over første kolonne ex. 16-12, over næste 17-12, osv.
Så datoerne ændrer sig, men tiderne, der er markeret i feltet flytter ikke med. Hvordan kan man lave det sådan, at den bestilte tid rykker sig i takt med, at datoen skifter, dvs. næste dag blot én tand til venstre???
17. december 2002 - 11:08
#2
I GUI-klassen oprettes bl.a. solskærmen indeholdende JTable, labels osv.
sunScreen = new JPanel();
sunScreen.setBounds(10, 10, 800, 600);
sunScreen.setLayout(null);
sunScreen.setBackground(lightBrown);
addTimeButton = new JButton();
addTimeButton.setBounds(650, 400, 120, 24);
addTimeButton.setBackground(darkBrown);
addTimeButton.setText("Bestil tid");
addTimeButton.addActionListener(this);
sunScreen.add(addTimeButton);
deleteTimeButton = new JButton();
deleteTimeButton.setBounds(650, 450, 120, 24);
deleteTimeButton.setBackground(darkBrown);
deleteTimeButton.setText("Afbestil tid");
deleteTimeButton.addActionListener(this);
sunScreen.add(deleteTimeButton);
logOutFromSunButton = new JButton();
logOutFromSunButton.setBounds(30, 520, 150, 24);
logOutFromSunButton.setBackground(darkBrown);
logOutFromSunButton.setText("Tilbage til profil");
logOutFromSunButton.addActionListener(this);
sunScreen.add(logOutFromSunButton);
//sunTableArray = new int[][]
//Bent = new int[];
Font myFont = new Font(null, 1, 15);
day1Label = new JLabel();
day1Label.setFont(myFont);
day1Label.setText(myGUIController.getCurrentDate());
day1Label.setBounds(100,80,70,20);
sunScreen.add(day1Label);
/*sunCurrentDateLabel1 = new JLabel();
sunCurrentDateLabel1.setFont(myFont);
sunCurrentDateLabel1.setText(
" "
+
+ " "
+ myGUIController.getNextDate()
+ " "
+ myGUIController.getNextDate()
+ " "
+ myGUIController.getNextDate()
+ " "
+ myGUIController.getNextDate()
+ " "
+ myGUIController.getNextDate()
+ " "
+ myGUIController.getNextDate());
sunCurrentDateLabel1.setBounds(100, 80, 500, 20);
sunScreen.add(sunCurrentDateLabel1);
*/
sunTimeTextArea = new JTextArea();
sunTimeTextArea.setBounds(50, 100, 45, 360);
sunTimeTextArea.setText(
" 09:00"
+ "\n"
+ " 09:30"
+ "\n"
+ " 10:00"
+ "\n"
+ " 10:30"
+ "\n"
+ " 11:00"
+ "\n"
+ " 11:30"
+ "\n"
+ " 12:00"
+ "\n"
+ " 12:30"
+ "\n"
+ " 13:00"
+ "\n"
+ " 13:30"
+ "\n"
+ " 14:00"
+ "\n"
+ " 14:30"
+ "\n"
+ " 15:00"
+ "\n"
+ " 15:30"
+ "\n"
+ " 16:00"
+ "\n"
+ " 16:30"
+ "\n"
+ " 17:00"
+ "\n"
+ " 17:30");
sunTimeTextArea.setFont(day1Label.getFont());
sunTimeTextArea.setOpaque(false);
sunTimeTextArea.setEditable(false);
sunTimeTextArea.setForeground(Color.black);
sunTimeTextArea.setFont(myFont);
//sunTimeTextArea.setBackground(Color.);
sunScreen.add(sunTimeTextArea);
sunTable = new JTable(18, 7);
sunTable.setBounds(100, 100, 500, 360);
sunTable.setRowHeight(20);
sunScreen.add(sunTable);
I den anden klasse ligger metoderne, der kaldes fra GUI.
public String getCurrentTime() {
calendarObject = Calendar.getInstance();
int currentHour = calendarObject.get(calendarObject.HOUR_OF_DAY);
int currentMinute = calendarObject.get(calendarObject.MINUTE);
if (currentMinute < 10) {
String t = ("") + currentHour + ":0" + currentMinute;
return t;
} else {
String t = ("") + currentHour + ":" + currentMinute;
return t;
}
}
public String getCurrentDate() {
calendarObject = Calendar.getInstance();
currentDayInt = calendarObject.get(calendarObject.DAY_OF_MONTH);
currentMonthInt = calendarObject.get(calendarObject.MONTH);
if (currentMonthInt < 12) {
currentMonthInt++;
} else if (currentMonthInt == 0) {
currentMonthInt = 1;
}
String currentDate = ("") + currentDayInt + "-" + currentMonthInt;
return currentDate;
}
public String getNextDate() {
if (currentDayInt != 31) {
currentDayInt++;
} else {
currentDayInt = 1;
currentMonthInt++;
}
if (currentMonthInt == 13) {
currentMonthInt = 1;
}
String nextDate = ("") + currentDayInt + "-" + currentMonthInt;
return nextDate;
}
public String bookSunTime() {
String booked = myUserDataBase.getCurrentUser();
return booked;
}
public String unBookSunTime() {
String unBooked = "";
return unBooked;
}
public void createNewUser() {
String u = myGUI.getNewUserName();
String n = myGUI.getNewUserNumber();
char[] p = myGUI.getNewPassword1();
String p1 = new String(p);
char[] pv = myGUI.getNewPassword2();
String p2 = new String(pv);
if (myUserDataBase.isUserExisting(u) == false) {
if (p1.equals("") == false && p2.equals("") == true) {
myGUI.verifyPasswordNotify();
} else if (p1.equals(p2) == true) {
myUserDataBase.addNewUser(u, p, n);
myGUI.clearAdminScreen();
myGUI.newUserAddedNotify();
} else
myGUI.diffPasswordsNotify();
} else
myGUI.userExistsNotify();
}
public void delUser() {
String u = myGUI.getNewUserName();
if (myUserDataBase.isUserExisting(u) == true) {
myUserDataBase.delUserFromDataBase(u);
myGUI.userDeletedNotify();
} else
myGUI.noUserNotify();
}
public void testSize() {
System.out.print("Der var så hul ");
myUserDataBase.printUsersSize();
}
//public void showUser() {
// String n = myGUI.getNewUserName();
// myUserDataBase.showUser(n);
//}
public void logInProfile() {
String n = myGUI.getUserName();
char[] p = (char[]) myGUI.getPassword();
if (myUserDataBase.isAdmin(n, p) == true) {
System.out.println("administrator login OK");
myGUI.adminScreenVisible();
}
if (myUserDataBase.isAdmin(n, p) == false
&& myUserDataBase.isUser(n) == true) {
if (myUserDataBase.isPassword(n, p) == true) {
System.out.println("User LogIn Succesful");
myGUI.updateTrainingFrequency(
myUserDataBase.getTrainingFrequency(n));
myGUI.profileScreenVisible();
System.out.println(getCurrentDate() + " ");
System.out.println(getCurrentTime());
}
if (myUserDataBase.isPassword(n, p) == false) {
myGUI.invalidPasswordNotify();
System.out.println("Pass was false");
}
}
if (myUserDataBase.isUser(n) == false
&& myUserDataBase.isAdmin(n, p) == false) {
myGUI.noUserNotify();
System.out.println("Ingen med det navn");
}
}
public void logInTraining() {
String n = myGUI.getUserName();
char[] p = (char[]) myGUI.getPassword();
if (myUserDataBase.isAdmin(n, p) == true) {
System.out.println("administrator login OK");
myGUI.adminScreenVisible();
}
if (myUserDataBase.isAdmin(n, p) == false
&& myUserDataBase.isUser(n) == true) {
if (myUserDataBase.isPassword(n, p) == true) {
if (myUserDataBase.isActive(n) == false) {
System.out.println("User LogIn Succesful");
System.out.println(myUserDataBase.isActive(n));
myUserDataBase.addToTrainingFrequency(n);
myUserDataBase.addToLogBook(n);
updateLogBookList();
myUserDataBase.addActiveUserToMap(n);
updateActiveUsersList();
myGUI.logInNotify();
} else
myGUI.alreadyActiveNotify();
}
if (myUserDataBase.isPassword(n, p) == false) {
myGUI.invalidPasswordNotify();
System.out.println("Pass was false");
}
}
if (myUserDataBase.isUser(n) == false
&& myUserDataBase.isAdmin(n, p) == false) {
myGUI.noUserNotify();
System.out.println("Ingen med det navn");
}
}
public void logOut() {
String n = myGUI.getUserName();
//if (n.equals(null) == true) {
char[] p = (char[]) myGUI.getPassword();
if (myUserDataBase.isPassword(n, p) == true) {
if (myUserDataBase.isActive(n) == true) {
myUserDataBase.setInactive(n);
myUserDataBase.delActiveUser(n);
System.out.println("User LogOut Succesful");
System.out.println(
"Brugerstatus = " + myUserDataBase.isActive(n));
myGUI.logOutNotify();
} else
myGUI.notLoggedInNotify();
}
if (myUserDataBase.isPassword(n, p) == false) {
myGUI.invalidPasswordNotify();
System.out.println("Pass was false");
}
if (myUserDataBase.isUser(n) == false
&& myUserDataBase.isAdmin(n, p) == false) {
System.out.println("Ingen med det navn");
}
}
public void updateActiveUsersList() {
myGUI.updateActiveUsersList(myUserDataBase.getActiveUsers());
}
public void updateLogBookList() {
myGUI.updateLogBookList(myUserDataBase.getLogBook());
}
public String getCurrentUserToGUI(){
return (String) myUserDataBase.getCurrentUser();
}
public Object getTrainingCard(){
return (Object) myUserDataBase.getTrainingCard();
}
public void loadUserDataBase() {
try {
mySerializedUserDataBaseFile = new SerializedUserDataBaseFile("userDataBase");
myUserDataBase = (UserDataBase) mySerializedUserDataBaseFile.getUserDataBase();
System.out.println("loaded?");
if (myUserDataBase == null){
myUserDataBase = new UserDataBase(this);
System.out.println("første gang for dig?");
}
} catch (IOException e) {
myUserDataBase = new UserDataBase(this);
System.out.println(e);
} catch (ClassNotFoundException e) {
System.out.println("no file on harddisk");
}
}
public void saveUserDataBase() {
try {
mySerializedUserDataBaseFile = new SerializedUserDataBaseFile("userDataBase");
mySerializedUserDataBaseFile.putUserDataBase(myUserDataBase);
System.out.println("UserDataBasen er Gemt");
} catch (IOException e) {
e.printStackTrace();
}
}
public void tieDateToSunTime(){
String n = getCurrentDate();
String p = n + myUserDataBase.getCurrentUser();
System.out.println(p);
}
}