谁能帮我把这个程序从程序员联合开发网上下下来啊??

http://www.pudn.com/downloads94/sourcecode/java/detail379345.html跪谢啊,高分啊... http://www.pudn.com/downloads94/sourcecode/java/detail379345.html
跪谢啊,高分啊
展开
 我来答
东边西边日出雨
2013-11-04
知道答主
回答量:20
采纳率:0%
帮助的人:9.2万
展开全部
/**
实验十一 显示表情 熟悉JAVA的事件处理机制
@author Yangxiaoyan CS0501
*/

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.*;

public class FaceTest
{

public static void main (String [] args)
{
FaceFrame frame =new FaceFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

}
}

class FaceFrame extends JFrame
{
DrawButton myPanel=new DrawButton();
String choice="happy";//定义首页是笑脸

public FaceFrame()
{
//Container con=getContentPane();
//con.setLayout(new BorderLayout());
setTitle("显示表情");
setSize(400,400);

JPanel down=new JPanel();
JButton button1 = new JButton("Happy");
JButton button2 = new JButton("Angry");
JButton button3 = new JButton("Cry");
JButton button4 = new JButton("Exit");

button1.addActionListener(new ButtonAction("happy"));
button2.addActionListener(new ButtonAction("angry"));
button3.addActionListener(new ButtonAction("cry"));
button4.addActionListener(new ButtonAction("exit"));

down.add(button1);
down.add(button2);
down.add(button3);
down.add(button4);
add(down,BorderLayout.SOUTH);

add(myPanel,BorderLayout.CENTER);//表情面板居中

}

class ButtonAction implements ActionListener
{
private String str;
public ButtonAction(String str){this.str=str;}
public void actionPerformed(ActionEvent e)
{
choice=str;
repaint();
}
}

class DrawButton extends JPanel
{

public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2=(Graphics2D) g;

g2.setPaint(Color.PINK);
g2.fillOval(100,100,200,150); //画脸型

if(choice.equals("happy")) //画微笑的脸
{
setBackground(Color.YELLOW);
g2.setPaint(Color.BLACK);
g2.drawArc(140,160,50,50,30,120);
g2.drawArc(210,160,50,50,30,120);
g2.drawArc(175,170,50,50,200,140);

}
if(choice.equals("angry")) //画生气的脸
{
setBackground(Color.RED);
g2.setPaint(Color.BLACK);
g2.drawLine(140,150,185,170);
g2.drawLine(215,170,260,150);
g2.drawLine(180,220,200,200);
g2.drawLine(200,200,220,220);

}
if(choice.equals("cry"))//画哭泣的脸
{
setBackground(Color.BLUE);
g2.setPaint(Color.BLACK);
g2.drawLine(140,170,185,150);
g2.drawLine(215,150,260,170);
g2.drawOval(180,200,40,20);
g2.drawOval(150,200,3,6);
g2.drawOval(180,170,3,9);
g2.drawOval(220,170,4,8);
g2.drawOval(250,210,2,6);
}
if(choice.equals("exit")) //退出
{
System.exit(0);
}
}
}
}
追问
复制粘贴下来格式不对啊,全是横着把代码写下去的,能弄成一个语句一行吗?
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式