为什么tf1.requestFocus();不聚焦;
为什么我写上了invalidate();validate();,还要缩放一下applet温度变化曲线才会出来!
刚学习这个,所以还不太熟悉,请帮下忙,下面是部分代码!!
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class LineGraph extends Applet implements ActionListener
{
int a1,a2,a3,a4,a5;
Label Title=new Label("Enter 5 daily temperatures and press ENTER in box 5");
Label day1=new Label("Day1");
TextField tf1=new TextField("");
Label day2=new Label("Day2");
TextField tf2=new TextField("");
Label day3=new Label("Day3");
TextField tf3=new TextField("");
Label day4=new Label("Day4");
TextField tf4=new TextField("");
Label day5=new Label("Day5");
TextField tf5=new TextField("");
public void init()
{
add(Title);
add(day1);
add(tf1);
add(day2);
add(tf2);
add(day3);
add(tf3);
add(day4);
add(tf4);
add(day5);
add(tf5);
tf5.addActionListener(this);
tf4.addActionListener(this);
tf3.addActionListener(this);
tf2.addActionListener(this);
tf1.addActionListener(this);
tf1.requestFocus();
}
public void paint(Graphics g)
{
g.drawLine(20,300,180,300); //温度变化曲线
g.drawLine(20, 70, 20, 300);
g.drawLine(20,(300-4*a1),60,(300-4*a2));
g.drawLine(60,(300-4*a2),100,(300-4*a3));
g.drawLine(100,(300-4*a3),140,(300-4*a4));
g.drawLine(140,(300-4*a4),180,(300-4*a5));
}
public void actionPerformed(ActionEvent arg0)
{
a1=Integer.parseInt(tf1.getText());
a2=Integer.parseInt(tf2.getText());
a3=Integer.parseInt(tf3.getText());
a4=Integer.parseInt(tf4.getText());
a5=Integer.parseInt(tf5.getText());
invalidate();
validate();
}
|
|