Java中可以锁住键盘吗??
请问 有 API 吗 ? 问题点数:50、回复次数:4Top
1 楼NoWant(NoWant)回复于 2001-11-06 08:43:04 得分 0
???Top
2 楼skyyoung(路人甲)回复于 2001-11-06 09:03:08 得分 50
屏幕的,要吗
Have an on-screen clock
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.text.*;
public class MyClock extends Applet {
MyPanel mp;
public void init() {
mp = new MyPanel(getParameter("format"));
add(mp);
}
}
class MyPanel extends Panel {
MyThread tm;
Color b, f;
SimpleDateFormat formatter;
String previousDateText = "";
String dateText;
MyPanel(String df) {
super();
formatter = new SimpleDateFormat(df);
validate();
setBackground(new Color(0).black);
setForeground(new Color(0).yellow);
b = this.getBackground();
f = this.getForeground();
tm = new MyThread(this);
tm.start();
}
public Dimension getPreferredSize() {
return new Dimension
(this.getFontMetrics(this.getFont()).stringWidth(getNow()) + 25, 30);
}
public void paint(Graphics g) {
if (g != null) {
g.setColor(b);
g.drawString(previousDateText,10,15);
g.setColor(f);
dateText = getNow();
g.drawString(dateText,10,15);
previousDateText = dateText;
}
}
public String getNow() {
return formatter.format(new Date());
}
}
class MyThread extends Thread {
MyPanel mp;
public MyThread(MyPanel a) {
mp = a;
}
public void run() {
while (true) {
try {
mp.repaint();
this.sleep(1000);
}
catch(InterruptedException e) { }
}
}
}
<HTML><HEAD></HEAD><BODY>
<APPLET CODE="MyClock.class"
HEIGHT=25 WIDTH=200>
<PARAM NAME="format" VALUE="yyyy-MM-dd hh:mm:ss">
</APPLET><P>
<APPLET CODE="MyClock.class"
HEIGHT=25 WIDTH=200>
<PARAM NAME="format" VALUE="h:mm a">
</APPLET><P>
<APPLET CODE="MyClock.class"
HEIGHT=25 WIDTH=200>
<PARAM NAME="format" VALUE="yyyy.MMMMM.dd GGG hh:mm aaa">
</APPLET><P>
<APPLET CODE="MyClock.class"
HEIGHT=25 WIDTH=200>
<PARAM NAME="format" VALUE="H:mm:ss:SSS">
</APPLET><P>
</BODY></HTML>
Top
3 楼skyyoung(路人甲)回复于 2001-11-06 09:04:48 得分 0
Set the computer clock
Define the following prototype in the header file JNIEXPORT void JNICALL Java_JavaHowTo_setSystemTime
(JNIEnv *, jobject, jshort, jshort);
the JNI function JNIEXPORT void JNICALL Java_JavaHowTo_setSystemTime
(JNIEnv *env, jobject obj, jshort hour, jshort minutes) {
SYSTEMTIME st;
GetLocalTime(&st);
st.wHour = hour;
st.wMinute = minutes;
SetLocalTime(&st);
}
The Java JNI wrapper would be class JavaHowTo {
public native void setSystemTime( short hour, short minutes);
static {
System.loadLibrary("javahowto");
}
}
And finally, to use it public class JNIJavaHowTo {
public static void main(String[] args) {
short hour = 10;
short minutes = 21;
// this example will set the system at 10h21 using the Windows API
// SetLocalTime.
JavaHowTo jht = new JavaHowTo();
// set the time at 10h21
jht.setSystemTime(hour, minutes);
}
}
Top
4 楼NoWant(NoWant)回复于 2001-11-06 19:41:02 得分 0
goodTop




