Hallo,
Ik ben aan het programmeren met java, maar ik heb een probleem. Ik heb een programma geschreven waarme de klok op de beeldscherm wordt zichtbaar. Ik wil to GUI gebruiken, maar het wilt niet helemaal. Hier onder heb ik de code's wat ik de code's. Misschien iemand mij kan helpen. Al vast bedankt.
public class Clock_maken extends java.applet.Applet
implements Runnable {
public volatile Thread clockThread = null;
JLabel Datuum_label;
DateFormat formatter;
Locale locale;
Date currentDate;
String today;
public void init(){
Locale = Locale.getDefault();
Datuum_label = new JLabel("date");
}
public void start() {
Datuum_label.setForeground(Color.black);
add(Datuum_label);
if(clockThread == null) {
clockThread = new Thread(this);
clockThread.start();
}
}
public void run() {
Thread myThread = Thread.currentThread();
while (clockThread == myThread) {
currentDate = new Date();
formatter =
DateFormat.getDateTimeInstance(DateFormat.FULL,
DateFormat.MEDIUM, locale);
today = formatter.format(currentDate);
Datuum_label.setText(today);
try {
Thread.sleep(1000);
} catch (InterruptedException e){ }
}
}
public void stop() {clockThread = null;}
/*
public static void main(String[] args){
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame lunarPhasesFrame = new JFrame("Lunar Phases");
lunarPhasesFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Clock_maken phases = new Clock_maken();
phases.init();
phases.start();
lunarPhasesFrame.pack();
lunarPhasesFrame.setVisible(true);
}
}*/
Hier heb ik mijn GUI Codes......................................................***//////////////////////////
///////////********************************///////////////////////////////////////////
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
/* JFrame lunarPhasesFrame = new JFrame("Lunar Phases");
lunarPhasesFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Clock_maken phases = new Clock_maken();
phases.init();
phases.start();
lunarPhasesFrame.pack();
lunarPhasesFrame.setVisible(true);*/
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Ik ben aan het programmeren met java, maar ik heb een probleem. Ik heb een programma geschreven waarme de klok op de beeldscherm wordt zichtbaar. Ik wil to GUI gebruiken, maar het wilt niet helemaal. Hier onder heb ik de code's wat ik de code's. Misschien iemand mij kan helpen. Al vast bedankt.
public class Clock_maken extends java.applet.Applet
implements Runnable {
public volatile Thread clockThread = null;
JLabel Datuum_label;
DateFormat formatter;
Locale locale;
Date currentDate;
String today;
public void init(){
Locale = Locale.getDefault();
Datuum_label = new JLabel("date");
}
public void start() {
Datuum_label.setForeground(Color.black);
add(Datuum_label);
if(clockThread == null) {
clockThread = new Thread(this);
clockThread.start();
}
}
public void run() {
Thread myThread = Thread.currentThread();
while (clockThread == myThread) {
currentDate = new Date();
formatter =
DateFormat.getDateTimeInstance(DateFormat.FULL,
DateFormat.MEDIUM, locale);
today = formatter.format(currentDate);
Datuum_label.setText(today);
try {
Thread.sleep(1000);
} catch (InterruptedException e){ }
}
}
public void stop() {clockThread = null;}
/*
public static void main(String[] args){
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame lunarPhasesFrame = new JFrame("Lunar Phases");
lunarPhasesFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Clock_maken phases = new Clock_maken();
phases.init();
phases.start();
lunarPhasesFrame.pack();
lunarPhasesFrame.setVisible(true);
}
}*/
Hier heb ik mijn GUI Codes......................................................***//////////////////////////
///////////********************************///////////////////////////////////////////
private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
/* JFrame lunarPhasesFrame = new JFrame("Lunar Phases");
lunarPhasesFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Clock_maken phases = new Clock_maken();
phases.init();
phases.start();
lunarPhasesFrame.pack();
lunarPhasesFrame.setVisible(true);*/
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}