📄 myframe.java
字号:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class myframe extends my_interface{
////*****构造函数*********/////
myframe() throws Exception{
tool=getToolkit();
setLayout(new BorderLayout());
b_Oval=new JButton("椭圆");
b_Rect=new JButton("矩形");
b_RoundRect=new JButton("圆矩形");
b_Line=new JButton("直线");
b_Arc=new JButton("圆弧");
b_OVAL=new JButton("圆形");
clear=new JButton("清空");
c_red=new JRadioButton("红色");
c_Yellow=new JRadioButton("黄色");
c_Green=new JRadioButton("绿色");
c_Black=new JRadioButton("黑色");
c_Blue=new JRadioButton("蓝色");
c6=new JRadioButton("调色板");
color=new ButtonGroup();
c_Black.setSelected(true);
t1=new TextField(3);
t2=new TextField(3);
l1=new Label("弧度");
l2=new Label(",");
///////*****填充******///////
fill=new ButtonGroup();
fillt=new JRadioButton("填充");
filln=new JRadioButton("不填充");
filln.setSelected(true);
panel_interface panel_class=(panel_interface)Class.forName("c_panel").newInstance();
Panel p=panel_class.panel(
b_Oval,
b_Rect,
b_RoundRect,
b_Line,
b_Arc,
b_OVAL,
clear,
c_red,
c_Yellow,
c_Green,
c_Black,
c_Blue,
c6,
color,
fill,
fillt,
filln,
t1,
t2,
l1,
l2
);
this.add(p,BorderLayout.SOUTH); //把面板添加到下方
clear.addActionListener(this);
b_Oval.addActionListener(this);
b_Rect.addActionListener(this);
b_RoundRect.addActionListener(this);
b_Line.addActionListener(this);
b_Arc.addActionListener(this);
b_OVAL.addActionListener(this);
clear.addKeyListener(this);
b_Oval.addKeyListener(this);
b_Rect.addKeyListener(this);
b_RoundRect.addKeyListener(this);
b_Line.addKeyListener(this);
b_Arc.addKeyListener(this);
b_OVAL.addKeyListener(this);
addMouseMotionListener(this); //添加鼠标监听器
addMouseListener(this);
/////****颜色*****////
c_red.addItemListener(this);
c_Yellow.addItemListener(this);
c_Green.addItemListener(this);
c_Black.addItemListener(this);
c_Blue.addItemListener(this);
c6.addItemListener(this);
c_red.addKeyListener(this);
c_Yellow.addKeyListener(this);
c_Green.addKeyListener(this);
c_Black.addKeyListener(this);
c_Blue.addKeyListener(this);
c6.addKeyListener(this);
///////*****填充******///////
fillt.addItemListener(this);
filln.addItemListener(this);
fillt.addKeyListener(this);
filln.addKeyListener(this);
//////******整合为一个panel******///////
////////*****设置frame属性,增加windows适配器*****///////
this.setBounds(0,0,800,400);
this.setVisible(true);
this.setTitle("05计本1班 李武洪");
this.setBackground(Color.pink);
// validate();
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
}
///////*******动作响应事件****/////////
public void actionPerformed(ActionEvent e){
try{
actionperformed_interface action_class=(actionperformed_interface)Class.forName("actionperformed").newInstance();
i=action_class.actionperformed(
i,
b_Oval,
b_Rect,
b_RoundRect,
b_Line,
b_Arc,
b_OVAL,
clear,
e);
if(i==0)
{
vector.removeAllElements();
}
repaint();
}
catch(Exception ee){
}
}
public void mouseMoved(MouseEvent e){
}
/////////******绘画******///////
public void paint(Graphics g){
// c_paint.c_paint(i,x1,y1,x2,y2,mouseflag,c,vector,tool,fillt,g);
try{
paint_interface paint_class=(paint_interface)Class.forName("c_paint").newInstance();
paint_class.paint(i,x1,y1,x2,y2,mouseflag,c,vector,tool,fillt,g,t1,t2);
}
catch(Exception e){
}
}
public void itemStateChanged(ItemEvent e){
try{
itemstatechanged_interface itemstatechanged_class=(itemstatechanged_interface)Class.forName("itemstatechanged").newInstance();
c=itemstatechanged_class.itemstatechanged(
c_red,
c_Yellow,
c_Green,
c_Black,
c_Blue,
c6,
e,
c
);
}
catch(Exception eee){
}
repaint();
}
public void mouseDragged(MouseEvent e){
x2=(int)e.getX(); //当鼠标拖动是把值赋给终点坐标x2,y2
y2=(int)e.getY();
mouseflag=1; //mouseflag为1,作用是划线的时候不会清空屏幕
repaint();
}
public void mousePressed(MouseEvent e){ //鼠标按下是获得起点坐标
x1=(int)e.getX();
y1=(int)e.getY();
}
public void mouseReleased(MouseEvent e){
//********当鼠标放开时,表示一次绘画结束,把图形的信息存入向量****////////
try{
mousereleased_interface mousereleased_class=(mousereleased_interface)Class.forName("mousereleased").newInstance();
mousereleased_class.mousereleased(
i,
fillt,
x1,
y1,
x2,
y2,
c,
vector,
t1,
t2
);
}
catch(Exception eeee){
}
mouseflag=0;
repaint();
}
public void keyPressed(KeyEvent e){
if(e.getKeyCode()==KeyEvent.VK_ESCAPE)
{
vector.removeAllElements();
repaint();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -