这个程序的要求是用paint方法显示一行字符串,包含“放大”和“缩小”按钮,当单击“放大”按钮时,显示的字符串字体放大一号,当单击“缩小”按钮时,显示的字符串字体缩小一号。
import java.awt.*;
import java.awt.event.*;
public class Change extends Frame implements ActionListener{
int size=20;
private Button big=new Button("放大");
private Button small=new Button("缩小");
private class WindowCloser extends WindowAdapter{
public void windowClosing(WindowEvent we){
System.exit(0);}
}
Font my=new Font("Dialog",Font.BOLD+Font.ITALIC,size);
String fonts="Hi,guy,best wishes"; public Change(){
super("this is change font");
setBackground(Color.green);
setup();big.addActionListener(this);
small.addActionListener(this);
addWindowListener(new WindowCloser());
show();
setSize(300,300);
}
public void setup(){
Panel buttons=new Panel();
buttons.setLayout(new FlowLayout());
buttons.add(big);
buttons.add(small);
setLayout(new BorderLayout());
add("South",buttons);
}
public void paint(Graphics g){
g.setFont(my);
g.drawString("Dialog"+fonts,50,50);
}
public void xiao(){
size-=1;
}
public void da(){
size+=1;}public void actionPerformed(ActionEvent e){
if(e.getSource()==small)
xiao();
else if(e.getSource()==big)
da();
repaint();
}
public static void main(String args[]){
Change x=new Change();
}
}
import java.awt.*;
import java.awt.event.*;
public class Change extends Frame implements ActionListener{
int size=20;
private Button big=new Button("放大");
private Button small=new Button("缩小");
private class WindowCloser extends WindowAdapter{
public void windowClosing(WindowEvent we){
System.exit(0);}
}
Font my=new Font("Dialog",Font.BOLD+Font.ITALIC,size);
String fonts="Hi,guy,best wishes"; public Change(){
super("this is change font");
setBackground(Color.green);
setup();big.addActionListener(this);
small.addActionListener(this);
addWindowListener(new WindowCloser());
show();
setSize(300,300);
}
public void setup(){
Panel buttons=new Panel();
buttons.setLayout(new FlowLayout());
buttons.add(big);
buttons.add(small);
setLayout(new BorderLayout());
add("South",buttons);
}
public void paint(Graphics g){
g.setFont(my);
g.drawString("Dialog"+fonts,50,50);
}
public void xiao(){
size-=1;
}
public void da(){
size+=1;}public void actionPerformed(ActionEvent e){
if(e.getSource()==small)
xiao();
else if(e.getSource()==big)
da();
repaint();
}
public static void main(String args[]){
Change x=new Change();
}
}
解决方案 »
- 关于快速排序的问题
- 关于接口的问题,谢谢
- 关于参数传递的问题
- 一个关于接口的简单问题
- 我写二个模块.一个是用java写的套接字client/server端,和另一个用VC写的套接字client/server端通讯,请问能否可以实现通讯?套接字用berkel
- 各位大侠,小弟问一下JBuilder6的问题
- 谁能讲的明白就送分,共同探讨一下关于static。
- ASP和JAVA哪个更有优势!希望大家发表一下自己的看法!参与者有分!!!
- String 如何转变为int
- 请教大虾,在Rose中怎么生成JAVA代码倒出?
- 关于spring的重复提交问题啊!有人知道怎么解决吗?
- 急急急。。。求救。关于不同包的消息对话框的对象
import java.awt.event.*;public class Change extends Frame implements ActionListener
{
int size = 44;
private Button big = new Button("放大");
private Button small = new Button("缩小"); private class WindowCloser extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
} Font my = new Font("Dialog", Font.BOLD + Font.ITALIC, size);
String fonts = "Hi,guy,best wishes"; public Change()
{
super("this is change font");
setBackground(Color.green);
setup(); big.addActionListener(this);
small.addActionListener(this);
addWindowListener(new WindowCloser());
show();
setSize(300, 300);
} public void setup()
{
Panel buttons = new Panel();
buttons.setLayout(new FlowLayout());
buttons.add(big);
buttons.add(small);
setLayout(new BorderLayout());
add("South", buttons);
} public void paint(Graphics g)
{
my=new Font("Dialog", Font.BOLD + Font.ITALIC, size);
g.setFont(my);
g.drawString("Dialog" + fonts, 50, 50);
} public void xiao()
{
size -= 1;
} public void da()
{
size += 1;
} public void actionPerformed(ActionEvent e)
{
if (e.getSource() == small)
xiao();
else if (e.getSource() == big)
da();
repaint();
} public static void main(String args[])
{
Change x = new Change();
}
}