import java.applet.*;
import java.awt.*;
public class checkboxdemo extends Applet
{
Checkbox checkbox1,checkbox2,checkbox3;
boolean lbool=false,bbool=false,ibool=false;
Button button1;
String text="";
public void init()
{
resize(320,200);
checkbox1=new Checkbox("LARGE");
checkbox2=new Checkbox("BOLD");
checkbox3=new Checkbox("ITALIC");
button1=new Button("clear");
add(checkbox1);
add(checkbox2);
add(checkbox3);
add(button1);
}
public boolean action(Event e,Object o)
{
if(e.target.equals(checkbox1))
{
lbool=!lbool;
}
if(e.target.equals(checkbox2))
{
bbool=!bbool;
}
if(e.target.equals(checkbox3))
{
ibool=!ibool;
}
if(e.target.equals(button1))
{
text="";
}
repaint(); //什么意思,起到什么作用!
return true; //返回真在本程序是什么意思?改成False也无碍!
}
public boolean keyDown(Event e,int k)
{
text=text+(char)k;
repaint();
return true;
}
public void paint(Graphics g)
{
String fontname="Roman";
int type=Font.PLAIN;
int size=24; //把什么设置成24?
Font font;
if(bbool)
{
type=type|Font.BOLD;
}
if(ibool)
{
type=type|Font.ITALIC;
}
if(lbool)
{
size=48;
}
font=new Font(fontname,type,size);
g.setFont(font);
g.drawString(text,20,100);
}
}
问题:
以上三句带颜色的句子都是什么意思?请高手赐教?多谢!!
----------------解决方案--------------------------------------------------------
首先是paint()方法,它在applet中显示文本,外形和图片,
你可以把Repaint();语句放进去强制执行paint()方法。
把你的applet窗体大小设置成24。
----------------解决方案--------------------------------------------------------
repaint(); 是刷新窗体!
个人认为int size=24;是
font=new Font(fontname,type,size);的一个参数,
只是字体大小吧!
如果说出大家指正!
----------------解决方案--------------------------------------------------------
对,应该是字体大小。呵呵,我没仔细看。
----------------解决方案--------------------------------------------------------
可我把int size改成48后,运行后也没有变化呀?
----------------解决方案--------------------------------------------------------
怎么没人帮我了?急死我了。多谢大哥大姐,
----------------解决方案--------------------------------------------------------
import java.applet.*;
import javax.swing.JCheckBox;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class checkboxdemo extends Applet
{
JCheckBox checkbox1,checkbox2,checkbox3;
JButton button1;
int type = Font.PLAIN;
int size=24;
String text=\"\";
public void init()
{
resize(320,200);
checkbox1=new JCheckBox(\"LARGE\", false);
checkbox2=new JCheckBox(\"BOLD\", false);
checkbox3=new JCheckBox(\"ITALIC\", false);
//Register a listener for the check boxes.
checkbox1.addActionListener(new checkboxdemo.FontTypeChoice());
checkbox2.addActionListener(new checkboxdemo.FontTypeChoice());
checkbox3.addActionListener(new checkboxdemo.FontTypeChoice());
button1=new JButton(\"clear\");
//Register a listener for button1.
button1.addActionListener(new MyButtonActionListener());
add(checkbox1);
add(checkbox2);
add(checkbox3);
add(button1);
}
public void paint(Graphics g)
{
super.paint(g);
String fontname=\"Roman\";
int type=Font.PLAIN;
Font font = new Font(fontname,type,size);
g.setFont(font);
g.drawString(text,20,100);
}
class FontTypeChoice implements ActionListener
{
/** Listens to the check boxes. */
public void actionPerformed(ActionEvent e)
{
String sizeStr = \"Normal\";
String typeStr = \"Plain\";
if((checkbox2.isSelected() == false) && (checkbox3.isSelected() == false))
{
type = Font.PLAIN;
typeStr = \"PLAIN\";
}
else if((checkbox3.isSelected()) && (checkbox2.isSelected() == false))
{
type = Font.ITALIC;
typeStr = \"ITALIC\";
}
else if(checkbox2.isSelected() && (checkbox3.isSelected() == false))
{
type = Font.BOLD;
typeStr = \"BOLD\";
}
else if(checkbox2.isSelected() && checkbox3.isSelected())
{
type = Font.BOLD | Font.ITALIC;
typeStr = \"BOLD | ITALIC\";
}
if(checkbox1.isSelected())
{
size = 48;
sizeStr = \"Large\";
}
else if(checkbox1.isSelected() == false)
{
size = 24;
sizeStr = \"Normal\";
}
text = sizeStr + \" \" + typeStr;
repaint();
}
}
class MyButtonActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object o = e.getSource();
if(o.equals(button1))
{
text=\"\";
checkbox1.setSelected(false);
checkbox2.setSelected(false);
checkbox3.setSelected(false);
repaint();
}
}
}
}
----------------解决方案--------------------------------------------------------
我天天上来看,怎么也没人给我回贴呀,是不是我问的有什么问题呀?NULL:你这是回答我问题呢还是问问题呢?我运行你的程序怎么老提示出问题呀?
----------------解决方案--------------------------------------------------------
小爪哇豆,
怎么不行了?你也说说不行的症状嘛,我这里调试是可以的.
----------------解决方案--------------------------------------------------------
编译到是成功了。就是网页上提示JAVA运行出错?
----------------解决方案--------------------------------------------------------