画图 画椭圆

package com.expriment;

//filename App14_1
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class huitu extends JFrame
{
     static JButton b1=new JButton("画圆");
     static JButton b2=new JButton("画椭圆");
     static JPanel pan=new MyPanel();
     static huitu frm = new huitu();
     static int circle=0;
     public static void main(String[] args)
     {
           //App14_1 frm=new App14_1();
           frm.setVisible(true);
           frm.setTitle("简单绘图应用程序");
           frm.setSize(300,250);
           frm.setLayout(null);
           frm.add(pan);
           pan.setBounds(0,0,300,250);
           frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);            
     }
     static class MyPanel extends JPanel implements ActionListener
     {
           MyPanel()
           {  
                      
                this.add(b1);   this.add(b2);      
                b1.addActionListener(this);
                b2.addActionListener(this);
            }
            public void actionPerformed(ActionEvent e)
            {
               JButton bt=(JButton)e.getSource();
               if (bt==b1) circle=1;
               else circle=2;
               Graphics g=this.getGraphics();
               repaint();
           }
            public void paintComponent(Graphics g)
           {
                super.paintComponent(g);
                b1.setBounds(50,180,80,25);
                b2.setBounds(150,180,80,25); 
                g.setFont(new Font("楷体",Font.ITALIC,20));
                g.setColor(Color.RED);
                g.drawString("画圆或椭圆",100,30);
                if (circle==1) g.drawOval(100,70,70,70);
                else if (circle==2) g.drawOval(80,40,70,120);
            }
     }        
}


在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值