📄 applet1.java
字号:
package com;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Applet1 extends Applet implements ActionListener
{
TextField tf,tf1;
TextArea ta;
Button bt;
public Applet1()
{
// super("运行程序");
tf=new TextField("运行程序",15);
tf1=new TextField("打开文件",45);
ta=new TextArea(20,60);
bt=new Button("运行");
}
public void init()
{
setSize(600,400);
setLocation(40,40);
setLayout(new FlowLayout());
add(tf);
add(tf1);
add(bt);
add(ta);
bt.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
/**打开一个新的进程*/ /*
ta.setText(ta.getText()+"执行actionPerformed(ActionEvent e)方法\n");
String str,str1;
str=tf.getText();
str1=tf1.getText();
if(str!=null && str1!=null)
{
String[] arg={str,str1};
try
{
ta.setText(ta.getText()+str+"打开\n");
Runtime rt=Runtime.getRuntime();
ta.setText(ta.getText()+str+"得到Runtime对象\n");
rt.exec(arg);
ta.setText(ta.getText()+str+"运行成功\n");
}
catch(Exception en)
{
ta.setText(ta.getText()+en.toString()+"\n");
}
}
*/
Graphics g=ta.getGraphics();
g.draw3DRect(20,20,150,40,false);
g.setColor(Color.RED);
g.setFont(new Font(null,Font.BOLD,20));
g.drawString("hello world !",30,50);
ta.print(g);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -