📄
字号:
10-例子1
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Example10_1 extends Applet implements ActionListener
{ Label label1,label2; TextField text1,text2;Button button;
public void init()
{ label1=new Label("我是第一个标签",Label.CENTER);
label2=new Label("我是第二个标签",Label.LEFT);
text1=new TextField(10); text2=new TextField(10);
button=new Button("确定"); add(label1);add(label2);
add(text1);add(text2); add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==button)
{ text1.setText(label1.getText()); text2.setText(label2.getText());
}
else
{}
}
}
10-例子2
import java.applet.*;
import java.awt.*;
public class Example10_2 extends Applet
{ Label label1,label2; TextField text1,text2;
public void init()
{ label1=new Label("输入姓名");
label2=new Label("输入性别");
label1.setBackground(Color.red);label1.setForeground(Color.blue);
text1=new TextField(10); text2=new TextField(10);
add(label1); add(text1);add(label2); add(text2);
}
}
10-例子3
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
class MyLabel extends Label implements ActionListener
{TextField text1;TextArea text2;int k=0;
MyLabel(String s)
{super(s);
text1=new TextField(10); text2=new TextArea(10,10);
text1.addActionListener(this); //标签作为文本框的监视器。
}
public void actionPerformed(ActionEvent e)
{ double n=0;text2.setText(null);
try{n=Double.valueOf(text1.getText()).doubleValue();
for(int i=1;i<=n;i++)
{if(n%i==0)
text2.append("\n"+i);
}
}
catch(NumberFormatException e1)
{text1.setText("请输入数字字符");
}
if(n%2==0)
{this.setBackground(Color.green);}
else
{this.setBackground(Color.yellow);}
}
}
public class Example10_3 extends Applet
{ MyLabel lab;
public void init()
{lab=new MyLabel("请输入一个数后按回车键");
add(lab);add(lab.text1);add(lab.text2);
}
}
10-例子4
import java.awt.*;import java.applet.*;
public class Example10_3 extends Applet
{public void init()
{MyLabel mylabel=new MyLabel();setLayout(null);
setLocation(12,12);add(mylabel);
}
}
class MyLabel extends Label
{ MyLabel()
{setSize(20,160);setBackground(Color.white);
}
public void paint(Graphics g)
{g.drawString("我",2,14); //在标签上写"我"。
g.drawString("是",2,34);
g.drawString("一",2,54);
g.drawString("个",2,74);
g.drawString("竖",2,94);
g.drawString("标",2,114);
g.drawString("签",2,134);
g.drawString("!",2,154);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -