编写一个java applet程序,有两个文本框组件,
3个回答
展开全部
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.applet.*;
public class AppletTest extends Applet
{
Label lb1;
Label lb2;
TextField tf1,tf2;
public void init()
{
lb1 = new Label("输入");
lb2 = new Label("输出");
tf1 = new TextField(5);
tf2 = new TextField(5);
tf1.requestFocus();
tf1.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER)
{
int num = Integer.parseInt(tf1.getText());
tf2.setText(String.valueOf(num*num));
}
else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
System.exit(0);
}
}
});
setLayout(new FlowLayout());
add(lb1);
add(tf1);
add(lb2);
add(tf2);
setSize(300,100);
}
}
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.applet.*;
public class AppletTest extends Applet
{
Label lb1;
Label lb2;
TextField tf1,tf2;
public void init()
{
lb1 = new Label("输入");
lb2 = new Label("输出");
tf1 = new TextField(5);
tf2 = new TextField(5);
tf1.requestFocus();
tf1.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER)
{
int num = Integer.parseInt(tf1.getText());
tf2.setText(String.valueOf(num*num));
}
else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
System.exit(0);
}
}
});
setLayout(new FlowLayout());
add(lb1);
add(tf1);
add(lb2);
add(tf2);
setSize(300,100);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自己先学会写写代码,这个一点不难! 调试不出来可以问问!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.event.KeyListener;
import java.applet.*;
public class AppletTest extends Applet
{
Label lb1;
Label lb2;
TextField tf1,tf2;
public void init()
{
lb1 = new Label("输入");
lb2 = new Label(
import java.applet.*;
public class AppletTest extends Applet
{
Label lb1;
Label lb2;
TextField tf1,tf2;
public void init()
{
lb1 = new Label("输入");
lb2 = new Label(
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询