import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.text.SimpleDateFormat;
public class NewFrame extends JFrame
{
JLabel lab1=new JLabel("设置日期:");
JLabel lab2=new JLabel("设置时间:");
JLabel lab3=new JLabel(" 标题:");
JTextField tf1=new JTextField();
JTextField tf2=new JTextField();
JTextField tf3=new JTextField();
JTextArea ta=new JTextArea();
JButton btnQue=new JButton("确定");
JButton btnCancle=new JButton("取消");
JLabel lab4=new JLabel(" ");
JLabel labCue = new JLabel("");
public NewFrame()
{
super();
setSize(500,600);
Container conn=getContentPane();
conn.setBounds(0,0,450,450);
lab1.setFont(new Font("宋体",Font.BOLD,15));
lab2.setFont(new Font("宋体",Font.BOLD,15));
lab3.setFont(new Font("宋体",Font.BOLD,15));
lab1.setBounds(20,20,90,20);
lab2.setBounds(20,60,90,20);
lab3.setBounds(20,100,90,20);
tf1.setBounds(100,20,200,20);
tf2.setBounds(100,60,200,20);
tf3.setBounds(100,100,200,20);
conn.add(lab1);
conn.add(tf1);
conn.add(lab2);
conn.add(tf2);
conn.add(lab3);
conn.add(tf3);
JScrollPane scroll=new JScrollPane(ta);
scroll.setBounds(20,150,400,200);
conn.add(scroll);
btnQue.setBounds(20,400,90,20);
ButtonHandler handler = new ButtonHandler();
btnQue.addActionListener(handler);
conn.add(btnQue);
btnCancle.setBounds(130,400,90,20);
conn.add(btnCancle);
conn.add(labCue);
labCue.setBounds(20,430,240,30);
lab4.setBounds(20,480,150,20);
conn.add(lab4);
SimpleDateFormat dateformatD=new SimpleDateFormat("yyyy/MM/dd");
SimpleDateFormat dateformatT=new SimpleDateFormat("HH:mm:ss");
Date date=new Date();
String now=(dateformatD.format(date)).toString();
String now1=(dateformatT.format(date)).toString();
tf1.setText(now);
tf2.setText(now1);
btnCancle.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
}
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnQue)
{
String sql=" ";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
JOptionPane.showMessageDialog(new Frame(),"确定");
String source="jdbc:odbc:xie";
Connection con=DriverManager.getConnection(source);
con.setAutoCommit(true);
Statement stmt=con.createStatement();
tf1.getText();
tf2.getText();
tf3.getText();
sql="INSERT INTO Table1(date, time, lab, thing) VALUES ('"+tf1.getText()+"', '"+tf2.getText()+"', '"+tf3.getText()+"', '"+ta.getText()+"')";
stmt.executeUpdate(sql);
labCue.setForeground(Color.green);
labCue.setText("数据插入成功");
}catch(Exception ew)
{
labCue.setForeground(Color.RED);
labCue.setText("数据插入失败");
}
}
}
}
public void rePaint()
{
tf3.setText(" ");
ta.setText(" ");
}
public static void main(String[] args)
{
NewFrame newframe=new NewFrame();
newframe.setVisible(true);
}
}
我想在这个frame中加入一个控制到时提醒的程序,该怎么加?我这写的是一个备忘录,要实现备忘到时提醒,该怎么弄?
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.text.SimpleDateFormat;
public class NewFrame extends JFrame
{
JLabel lab1=new JLabel("设置日期:");
JLabel lab2=new JLabel("设置时间:");
JLabel lab3=new JLabel(" 标题:");
JTextField tf1=new JTextField();
JTextField tf2=new JTextField();
JTextField tf3=new JTextField();
JTextArea ta=new JTextArea();
JButton btnQue=new JButton("确定");
JButton btnCancle=new JButton("取消");
JLabel lab4=new JLabel(" ");
JLabel labCue = new JLabel("");
public NewFrame()
{
super();
setSize(500,600);
Container conn=getContentPane();
conn.setBounds(0,0,450,450);
lab1.setFont(new Font("宋体",Font.BOLD,15));
lab2.setFont(new Font("宋体",Font.BOLD,15));
lab3.setFont(new Font("宋体",Font.BOLD,15));
lab1.setBounds(20,20,90,20);
lab2.setBounds(20,60,90,20);
lab3.setBounds(20,100,90,20);
tf1.setBounds(100,20,200,20);
tf2.setBounds(100,60,200,20);
tf3.setBounds(100,100,200,20);
conn.add(lab1);
conn.add(tf1);
conn.add(lab2);
conn.add(tf2);
conn.add(lab3);
conn.add(tf3);
JScrollPane scroll=new JScrollPane(ta);
scroll.setBounds(20,150,400,200);
conn.add(scroll);
btnQue.setBounds(20,400,90,20);
ButtonHandler handler = new ButtonHandler();
btnQue.addActionListener(handler);
conn.add(btnQue);
btnCancle.setBounds(130,400,90,20);
conn.add(btnCancle);
conn.add(labCue);
labCue.setBounds(20,430,240,30);
lab4.setBounds(20,480,150,20);
conn.add(lab4);
SimpleDateFormat dateformatD=new SimpleDateFormat("yyyy/MM/dd");
SimpleDateFormat dateformatT=new SimpleDateFormat("HH:mm:ss");
Date date=new Date();
String now=(dateformatD.format(date)).toString();
String now1=(dateformatT.format(date)).toString();
tf1.setText(now);
tf2.setText(now1);
btnCancle.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
}
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnQue)
{
String sql=" ";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
JOptionPane.showMessageDialog(new Frame(),"确定");
String source="jdbc:odbc:xie";
Connection con=DriverManager.getConnection(source);
con.setAutoCommit(true);
Statement stmt=con.createStatement();
tf1.getText();
tf2.getText();
tf3.getText();
sql="INSERT INTO Table1(date, time, lab, thing) VALUES ('"+tf1.getText()+"', '"+tf2.getText()+"', '"+tf3.getText()+"', '"+ta.getText()+"')";
stmt.executeUpdate(sql);
labCue.setForeground(Color.green);
labCue.setText("数据插入成功");
}catch(Exception ew)
{
labCue.setForeground(Color.RED);
labCue.setText("数据插入失败");
}
}
}
}
public void rePaint()
{
tf3.setText(" ");
ta.setText(" ");
}
public static void main(String[] args)
{
NewFrame newframe=new NewFrame();
newframe.setVisible(true);
}
}
我想在这个frame中加入一个控制到时提醒的程序,该怎么加?我这写的是一个备忘录,要实现备忘到时提醒,该怎么弄?
现在是 程序启动超出10秒我就让他弹出对话框import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import java.text.*;
import java.text.SimpleDateFormat;
import java.util.*;public class Test15 extends JFrame
{
JLabel lab1=new JLabel("设置日期:");
JLabel lab2=new JLabel("设置时间:");
JLabel lab3=new JLabel(" 标题:");
JTextField tf1=new JTextField();
JTextField tf2=new JTextField();
JTextField tf3=new JTextField();
JTextArea ta=new JTextArea();
JButton btnQue=new JButton("确定");
JButton btnCancle=new JButton("取消");
JLabel lab4=new JLabel(" ");
JLabel labCue = new JLabel("");
public Test15()
{
super();
setSize(500,600);
Container conn=getContentPane();
conn.setBounds(0,0,450,450);
lab1.setFont(new Font("宋体",Font.BOLD,15));
lab2.setFont(new Font("宋体",Font.BOLD,15));
lab3.setFont(new Font("宋体",Font.BOLD,15)); lab1.setBounds(20,20,90,20);
lab2.setBounds(20,60,90,20);
lab3.setBounds(20,100,90,20);
tf1.setBounds(100,20,200,20);
tf2.setBounds(100,60,200,20);
tf3.setBounds(100,100,200,20);
conn.add(lab1);
conn.add(tf1);
conn.add(lab2);
conn.add(tf2);
conn.add(lab3);
conn.add(tf3);
JScrollPane scroll=new JScrollPane(ta);
scroll.setBounds(20,150,400,200);
conn.add(scroll);
btnQue.setBounds(20,400,90,20);
ButtonHandler handler = new ButtonHandler();
btnQue.addActionListener(handler);
conn.add(btnQue);
btnCancle.setBounds(130,400,90,20);
conn.add(btnCancle);
conn.add(labCue);
labCue.setBounds(20,430,240,30);
lab4.setBounds(20,480,150,20);
conn.add(lab4);
SimpleDateFormat dateformatD=new SimpleDateFormat("yyyy/MM/dd");
SimpleDateFormat dateformatT=new SimpleDateFormat("HH:mm:ss");
Date date=new Date();
String now=(dateformatD.format(date)).toString();
String now1=(dateformatT.format(date)).toString();
tf1.setText(now);
tf2.setText(now1);
btnCancle.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
//以下四行,现记录当前程序启动时的时间,然后启动线程
long oldTime = System.currentTimeMillis();
CountTime ct = new CountTime( oldTime );
//System.out.println( oldTime );
ct.start();
}
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnQue)
{
String sql=" ";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
JOptionPane.showMessageDialog(new Frame(),"确定");
String source="jdbc:odbc:xie";
Connection con=DriverManager.getConnection(source);
con.setAutoCommit(true);
Statement stmt=con.createStatement();
tf1.getText();
tf2.getText();
tf3.getText();
sql="INSERT INTO Table1(date, time, lab, thing) VALUES ('"+tf1.getText()+"', '"+tf2.getText()+"', '"+tf3.getText()+"', '"+ta.getText()+"')";
stmt.executeUpdate(sql);
labCue.setForeground(Color.green);
labCue.setText("数据插入成功");
}catch(Exception ew)
{
labCue.setForeground(Color.RED);
labCue.setText("数据插入失败");
}
}
}
}
public void rePaint()
{
tf3.setText(" ");
ta.setText(" ");
}
public static void main(String[] args)
{
Test15 newframe=new Test15();
newframe.setVisible(true);
} }
//以下的多线程类,实现时间计算功能
class CountTime extends Thread
{
long oldTime = 0;
CountTime( long oldTime )
{
this.oldTime = oldTime;
}
public void run()
{
while(true)
{
//get recent system time
long newTime = System.currentTimeMillis();
//System.out.println( newTime );
if( newTime - this.oldTime >= 10000 )
{
JOptionPane.showMessageDialog( new Frame(), "TIME OUT" );
System.exit( 0 );
}
}
}
}
//以下四行,现记录当前程序启动时的时间,然后启动线程
long oldTime = System.currentTimeMillis();
CountTime ct = new CountTime( oldTime );
//System.out.println( oldTime );
ct.start();
}
//以下的多线程类,实现时间计算功能
class CountTime extends Thread
{
long oldTime = 0;
CountTime( long oldTime )
{
this.oldTime = oldTime;
}
public void run()
{
while(true)
{
//get recent system time
long newTime = System.currentTimeMillis();
//System.out.println( newTime );
if( newTime - this.oldTime >= 10000 )
{
JOptionPane.showMessageDialog( new Frame(), "TIME OUT" );
System.exit( 0 );
}
}
}
}