麻煩大家幫我看一下,我想點擊設定按鈕彈出另外一個視窗來設定鬧鐘時間,但是運行的時候就像下面這樣什么都不顯示

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Clock extends JFrame{
public Graphics mg;
JButton set,ok;
JLabel label,label1;
JFrame frame1,frame2;
JTextField time1,time2;
int a=0,b=0;//獲取輸入框中的字串
public Clock(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
frame1 = new JFrame("時鐘");
frame1.setSize(300,300);
frame1.setLocation(600,250);
set = new JButton("設定");
mg = this.getGraphics();
add(set);
set.setLocation(10, 5);//設定按鈕位置、大小
frame1.setVisible(true);
set.addActionListener(new Alarm());
}
class Alarm implements ActionListener{
public void actionPerformed(ActionEvent e) {
closeThis(frame1);
frame2 = new JFrame("設定");
frame2.setSize(200,200);
frame2.setLocation(600,250);
ok=new JButton("確定");
label=new JLabel("設定鬧鐘時間:");
label1=new JLabel(" : ");
time1=time2=new JTextField();
add(label); add(label1);
add(time1); add(time2); add(ok);
label.setLocation(10, 10);
time1.setBounds(20, 10, 10, 5);
time2.setBounds(20, 30, 10, 5);
label1.setLocation(20, 20);
ok.setLocation(40, 30);
ok.addActionListener(new Back());
frame2.setVisible(true);
a=Integer.parseInt(time1.getText());
b=Integer.parseInt(time2.getText());
}
}
class Back implements ActionListener{
public void actionPerformed(ActionEvent e) {
closeThis(frame2);
frame1.setVisible(true);
}
}
public void paint(Graphics mg){
int hh=16,mm=30,ss=0;//測驗用,獲取當前時間的代碼暫時沒寫
if(a==hh&&b==mm&&ss==0)//設定時間與當前時間相同
JOptionPane.showMessageDialog(this,"時間到!","鬧鐘", JOptionPane.INFORMATION_MESSAGE);
}
public void closeThis(JFrame frame){
frame.dispose();
}
public static void main(String[] args) {
new Clock();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/59174.html
標籤:Java相關
