Java程序 达到基本要求就可以 课题代号: 2 课题名称:简单画板程序 课题要求: ①基本要求:
package draw;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
//the point
//impress the info of one point,the x and y
class OnePoint implements Serializable
{
int x;
int y;
int tool;
Color c;
int border;
public OnePoint(int x,int y,int tool,Color cc,int border)
{
this.x=x;
this.y=y;
this.tool=tool;
this.c=cc;
this.border=border;
}
public static void main(String[] args)
{
DrawingBoard oneBorder=new DrawingBoard();
}
}
class DrawingBoard extends Frame implements MouseListener,ItemListener,ActionListener,MouseMotionListener
{
Button pen,line,ellipse,rect,clear,colorboard,storebutton,openbutton;
Choice sizechoice,colorchoice ;
Label pensize, pencolor;
Panel panel ;
FileDialog storefile, openfile;
FileInputStream filein;
FileOutputStream fileout;
ObjectInputStream objectin;
ObjectOutputStream objectout;
int mode=0;
int flagtool=0;
Color flagcolor;
int border;
BasicStroke size;
private Point2D[] p=new Point2D[3];;
OnePoint p1,p2;
Vector points=new Vector();
public DrawingBoard()
{
pen=new Button("画笔");
line=new Button("直线");
ellipse=new Button("圆");
rect=new Button("矩形");
clear=new Button("清除");
colorboard=new Button("调色板");
storebutton=new Button("存储文件");
openbutton=new Button("打开文件");
pensize=new Label("画笔大小");
pencolor=new Label("画笔颜色");
storefile=new FileDialog(this,"存储文件",FileDialog.SAVE);
storefile.setVisible(false);
storefile.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
storefile.setVisible(false);
}
});
openfile=new FileDialog(this,"打开文件",FileDialog.LOAD);
openfile.setVisible(false);
openfile.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
openfile.setVisible(false);
}
});
sizechoice=new Choice();
sizechoice.add("1");
sizechoice.add("2");
sizechoice.add("4");
sizechoice.add("6");
sizechoice.add("8");
sizechoice.addItemListener(this);
colorchoice=new Choice();
colorchoice.add("black");
colorchoice.add("red");
colorchoice.add("blue");
colorchoice.add("green");
colorchoice.addItemListener(this);
pen.addActionListener(this);
line.addActionListener(this);
ellipse.addActionListener(this);
rect.addActionListener(this);
clear.addActionListener(this);
colorboard.addActionListener(this);
storebutton.addActionListener(this);
openbutton.addActionListener(this);
panel=new Panel();
panel.add(storebutton);
panel.add(openbutton);
panel.add(pen);
panel.add(line);
panel.add(ellipse);
panel.add(rect);
panel.add(clear);
panel.add(sizechoice);
panel.add(pensize);
panel.add(colorchoice);
panel.add(pencolor);
panel.add(colorboard);
add(panel,BorderLayout.NORTH);
setBounds(100,100,700,600);
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
/**
* 添加鼠标事件的监听器,否则,鼠标的移动和点击都将无法识别!
* */
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
Graphics2D g2d=(Graphics2D)g;
if(flagtool==2)
{ //qing chu
g.clearRect(0,0,getSize().width,getSize().height);
}
for(int i=0;i<points.size()-1;i++)
{
p1=(OnePoint)points.elementAt(i);
p2=(OnePoint)points.elementAt(i+1);
g2d.setColor(p1.c); //////////////需要使用Graphics2D从Graphics类中继承下来的方法 setColor()设置当前的颜色
size=new BasicStroke(p1.border,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);
g2d.setStroke(size);
if(p1.tool==p2.tool)
{
switch(p1.tool)
{
case 0:
Line2D.Double line1=new Line2D.Double(p1.x,p1.y,p2.x,p2.y);
g2d.draw(line1);
break;
case 1:
Line2D.Double line2=new Line2D.Double(p1.x,p1.y,p2.x,p2.y);
g2d.draw(line2);
break;
case 3:
Ellipse2D.Double ellipse=new Ellipse2D.Double(p1.x,p1.y,Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y));
g2d.draw(ellipse);
break;
case 4:
Rectangle2D.Double rect=new Rectangle2D.Double(p1.x,p1.y,Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y));
g2d.draw(rect);
break;
default:
}
}
}
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) //鼠标点下时候,将当前的点信息记录
{
mode=0;
p[0]=e.getPoint();
OnePoint pp1=new OnePoint(e.getX(),e.getY(),flagtool,flagcolor,border);
points.addElement(pp1);
//repaint();
}
public void mouseReleased(MouseEvent e) //鼠标松开时候,如果是画笔,则当前截断,是其余状态记下一枚点信息
{
mode=1;
if(flagtool==0)
{
points.addElement(new OnePoint(-1,-1,22,flagcolor,border));
}
else
{
OnePoint pp2=new OnePoint(e.getX(),e.getY(),flagtool,flagcolor,border);
points.addElement(pp2);
points.add(new OnePoint(-1,-1,22,flagcolor,border));
}
repaint();
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==colorchoice)
{
String selected=colorchoice.getSelectedItem();
if(selected=="black"){flagcolor=new Color(0,0,0); }
else if(selected=="red"){flagcolor=new Color(255,0,0); }
else if(selected=="blue"){ flagcolor=new Color(0,0,255);}
else if(selected=="green"){ flagcolor=new Color(0,255,0); }
}
else if(e.getSource()==sizechoice)
{
String selected=sizechoice.getSelectedItem();
if (selected=="1"){ border=1; }
else if(selected=="2"){ border=2*2; }
else if(selected=="4"){ border=4*2; }
else if(selected=="6"){ border=6*2; }
else if(selected=="8"){ border=8*2; }
}
}
/*public void update(Graphics g) { //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
paint(g);
} */
public void actionPerformed(ActionEvent e)
{
// TODO Auto-generated method stub
if(e.getSource()==pen){flagtool=0; }
else if(e.getSource()==line){ flagtool=1; }
else if(e.getSource()==clear)
{
flagtool=2;
points.removeAllElements();
repaint(); //此语要有,否则今生无法删除!
}
else if(e.getSource()==ellipse){ flagtool=3; }
else if(e.getSource()==rect){ flagtool=4; }
else if(e.getSource()==colorboard)
{
/*
* 使用 javax.swing.×包中的 JColorChooser 类的静态方法showDialog(Component component,String title,Color color ),
* 该方法的参数,component是当前显示对话框的父框架,color是设置调色板初始的被选颜色
*
* 该方法返回被选的颜色,类型为Color
* */
Color color=JColorChooser.showDialog(this, "调色板",flagcolor);
flagcolor=color;
}
else if(e.getSource()==openbutton)
{
openfile.setVisible(true);
if(openfile.getFile()!=null)
{
int temp=flagtool;
flagtool=2;
repaint();
try{
points.removeAllElements();
File file=new File(openfile.getDirectory(),openfile.getFile());
filein=new FileInputStream(file);
objectin=new ObjectInputStream(filein);
points=(Vector)objectin.readObject();
objectin.close();
filein.close();
flagtool=temp;
repaint();
}
catch(Exception ee){ System.out.println(ee.toString()); }
}
}
else if(e.getSource()==storebutton)
{
storefile.setVisible(true);
if(storefile.getFile()!=null)
{
try {
File file=new File(storefile.getDirectory(),storefile.getFile());
fileout=new FileOutputStream(file);
objectout=new ObjectOutputStream(fileout);
objectout.writeObject(points);
objectout.close();
fileout.close();
repaint();
}
catch (FileNotFoundException e1)
{
System.out.println(e1.toString());
e1.printStackTrace();
} catch (IOException ee) {
System.out.println(ee.toString());
ee.printStackTrace();
}
}
}
}
public void mouseDragged(MouseEvent e) //鼠标拖动时候,//当且仅当 flagtool==0,或者表示为橡皮的时候
//才将拖动过程中涉及到的点全部记录下来,并且调用repain()方法,重画当前
// TODO Auto-generated method stub
{
if(flagtool==0)
{
OnePoint pp3=new OnePoint(e.getX(),e.getY(),flagtool,flagcolor,border);
points.addElement(pp3);
repaint();
}
if(flagtool==1)
{
OnePoint pp3=new OnePoint(e.getX(),e.getY(),flagtool,flagcolor,border);
repaint();
}
}
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
}
}
package Newtest;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame2 extends JFrame {
JPanel contentPane;
JMenuBar jMenuBar1 = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileExit = new JMenuItem();
JMenu jMenuHelp = new JMenu();
JMenuItem jMenuHelpAbout = new JMenuItem();
JToolBar jToolBar = new JToolBar();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
ImageIcon image1;
ImageIcon image2;
ImageIcon image3;
JLabel statusBar = new JLabel();
BorderLayout borderLayout1 = new BorderLayout();
JMenuItem jMenuItem2 = new JMenuItem();
JMenu jMenu1 = new JMenu();
JMenuItem jMenuItem1 = new JMenuItem();
JMenuItem jMenuItem3 = new JMenuItem();
JMenu jMenu2 = new JMenu();
JMenuItem jMenuItem4 = new JMenuItem();
JMenuItem jMenuItem5 = new JMenuItem();
JMenuItem jMenuItem6 = new JMenuItem();
JTextArea jTextArea1 = new JTextArea();
//Construct the frame
public Frame2() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
image1 = new ImageIcon(Newtest.Frame2.class.getResource("openFile.png"));
image2 = new ImageIcon(Newtest.Frame2.class.getResource("closeFile.png"));
image3 = new ImageIcon(Newtest.Frame2.class.getResource("help.png"));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Note Test");
statusBar.setText(" ");
jMenuFile.setText("File");
jMenuFileExit.setText("Exit");
jMenuFileExit.addActionListener(new Frame2_jMenuFileExit_ActionAdapter(this));
jMenuHelp.setText("Help");
jMenuHelpAbout.setText("About");
jMenuHelpAbout.addActionListener(new Frame2_jMenuHelpAbout_ActionAdapter(this));
jButton1.setIcon(image1);
jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this));
jButton1.setToolTipText("Open File");
jButton2.setIcon(image2);
jButton2.setToolTipText("Close File");
jButton3.setIcon(image3);
jButton3.setToolTipText("Help");
jMenuItem2.setText("Save");
jMenu1.setText("Open");
jMenuItem1.setText("Text1");
jMenuItem3.setText("Text2");
jMenu2.setText("Edit");
jMenuItem4.setText("Copy");
jMenuItem5.setText("Paste");
jMenuItem6.setText("Detele");
jTextArea1.setToolTipText("");
jTextArea1.setText("");
jToolBar.add(jButton1);
jToolBar.add(jButton2);
jToolBar.add(jButton3);
jMenuFile.add(jMenu1);
jMenuFile.add(jMenuItem2);
jMenuFile.addSeparator();
jMenuFile.add(jMenuFileExit);
jMenuHelp.add(jMenuHelpAbout);
jMenuBar1.add(jMenuFile);
jMenuBar1.add(jMenu2);
jMenuBar1.add(jMenuHelp);
this.setJMenuBar(jMenuBar1);
contentPane.add(jToolBar, BorderLayout.NORTH);
contentPane.add(statusBar, BorderLayout.SOUTH);
contentPane.add(jTextArea1, BorderLayout.CENTER);
jMenu1.add(jMenuItem1);
jMenu1.add(jMenuItem3);
jMenu2.add(jMenuItem4);
jMenu2.add(jMenuItem5);
jMenu2.add(jMenuItem6);
}
//File | Exit action performed
public void jMenuFileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
//Help | About action performed
public void jMenuHelpAbout_actionPerformed(ActionEvent e) {
Frame2_AboutBox dlg = new Frame2_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
dlg.show();
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
jMenuFileExit_actionPerformed(null);
}
}
void jButton1_actionPerformed(ActionEvent e) {
}
}
class Frame2_jMenuFileExit_ActionAdapter implements ActionListener {
Frame2 adaptee;
Frame2_jMenuFileExit_ActionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuFileExit_actionPerformed(e);
}
}
class Frame2_jMenuHelpAbout_ActionAdapter implements ActionListener {
Frame2 adaptee;
Frame2_jMenuHelpAbout_ActionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jMenuHelpAbout_actionPerformed(e);
}
}
class Frame2_jButton1_actionAdapter implements java.awt.event.ActionListener {
Frame2 adaptee;
Frame2_jButton1_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.awt.geom.*;
import java.io.*;
@SuppressWarnings({"serial","unused"})
class Point implements Serializable
{
int x,y;
Color col;
int tool;
int boarder;
Point(int x, int y, Color col, int tool, int boarder)
{
this.x = x;
this.y = y;
this.col = col;
this.tool = tool;
this.boarder = boarder;
}
}
@SuppressWarnings({"serial","unused"})
class paintboard extends Frame implements ActionListener,MouseMotionListener,MouseListener,ItemListener
{
int x = -1, y = -1;
int con = 1;//画笔大小
int Econ = 5;//橡皮大小
int toolFlag = 0;//toolFlag:工具标记
//toolFlag工具对应表:
//(0--画笔);(1--橡皮);(2--清除);
//(3--直线);(4--圆);(5--矩形);
Color c = new Color(0,0,0); //画笔颜色
BasicStroke size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);//画笔粗细
Point cutflag = new Point(-1, -1, c, 6, con);//截断标志
@SuppressWarnings("unchecked")
Vector paintInfo = null;//点信息向量组
int n = 1;
FileInputStream picIn = null;
FileOutputStream picOut = null;
ObjectInputStream VIn = null;
ObjectOutputStream VOut = null;
// *工具面板--画笔,直线,圆,矩形,多边形,橡皮,清除*/
Panel toolPanel;
Button eraser, drLine,drCircle,drRect;
Button clear ,pen;
Choice ColChoice,SizeChoice,EraserChoice;
Button colchooser;
Label 颜色,大小B,大小E;
//保存功能
//Button openPic,savePic;
FileDialog openPicture,savePicture;
@SuppressWarnings("unchecked")
paintboard(String s)
{
super(s);
addMouseMotionListener(this);
addMouseListener(this);
paintInfo = new Vector();
/*各工具按钮及选择项*/
//颜色选择
ColChoice = new Choice();
ColChoice.add("black");
ColChoice.add("red");
ColChoice.add("blue");
ColChoice.add("green");
ColChoice.addItemListener(this);
//画笔大小选择
SizeChoice = new Choice();
SizeChoice.add("1");
SizeChoice.add("3");
SizeChoice.add("5");
SizeChoice.add("7");
SizeChoice.add("9");
SizeChoice.addItemListener(this);
//橡皮大小选择
EraserChoice = new Choice();
EraserChoice.add("5");
EraserChoice.add("9");
EraserChoice.add("13");
EraserChoice.add("17");
EraserChoice.addItemListener(this);
////////////////////////////////////////////////////
toolPanel = new Panel();
clear = new Button("清除");
eraser = new Button("橡皮");
pen = new Button("画笔");
drLine = new Button("画直线");
drCircle = new Button("画圆形");
drRect = new Button("画矩形");
colchooser = new Button("显示调色板");
clear.setBackground(Color.GREEN);
drRect.setBackground(Color.GREEN);
pen.setBackground(Color.GREEN);
eraser.setBackground(Color.GREEN);
drLine.setBackground(Color.GREEN);
drCircle.setBackground(Color.GREEN);
colchooser.setBackground(Color.GREEN);
//各组件事件监听
clear.addActionListener(this);
eraser.addActionListener(this);
pen.addActionListener(this);
drLine.addActionListener(this);
drCircle.addActionListener(this);
drRect.addActionListener(this);
colchooser.addActionListener(this);
颜色 = new Label("画笔颜色",Label.CENTER);
大小B = new Label("画笔大小",Label.CENTER);
大小E = new Label("橡皮大小",Label.CENTER);
颜色.setBackground(Color.gray);
大小B.setBackground(Color.gray);
大小E.setBackground(Color.gray);
//面板添加组件
toolPanel.add(pen);
toolPanel.add(drLine);
toolPanel.add(drCircle);
toolPanel.add(drRect);
toolPanel.add(颜色); toolPanel.add(ColChoice);
toolPanel.add(大小B); toolPanel.add(SizeChoice);
toolPanel.add(colchooser);
toolPanel.add(eraser);
toolPanel.add(大小E); toolPanel.add(EraserChoice);
toolPanel.add(clear);
//工具面板到APPLET面板
add(toolPanel,BorderLayout.NORTH);
setBounds(60,60,900,600); setVisible(true);
validate();
//dialog for save and load
openPicture = new FileDialog(this,"打开图画",FileDialog.LOAD);
openPicture.setVisible(false);
savePicture = new FileDialog(this,"保存图画",FileDialog.SAVE);
savePicture.setVisible(false);
openPicture.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ openPicture.setVisible(false); }
});
savePicture.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ savePicture.setVisible(false); }
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ System.exit(0);}
});
}
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
Point p1,p2;
n = paintInfo.size();
if(toolFlag==2)
g.clearRect(0,0,getSize().width,getSize().height);//清除
for(int i=1; i<n ;i++){
p1 = (Point)paintInfo.elementAt(i-1);
p2 = (Point)paintInfo.elementAt(i);
size = new BasicStroke(p1.boarder,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);
g2d.setColor(p1.col);
g2d.setStroke(size);
if(p1.tool==p2.tool)
{
switch(p1.tool)
{
case 0://画笔
Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
g2d.draw(line1);
break;
case 1://橡皮
g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder);
break;
case 3://画直线
Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
g2d.draw(line2);
break;
case 4://画圆
Ellipse2D ellipse = new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x-p1.x) , Math.abs(p2.y-p1.y));
g2d.draw(ellipse);
break;
case 5://画矩形
Rectangle2D rect = new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x-p1.x) , Math.abs(p2.y-p1.y));
g2d.draw(rect);
break;
case 6://截断,跳过
i=i+1;
break;
default :
}//end switch
}//end if
}//end for
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource()==ColChoice)//预选颜色
{
String name = ColChoice.getSelectedItem();
if(name=="black")
{c = new Color(0,0,0); }
else if(name=="red")
{c = new Color(255,0,0);}
else if(name=="green")
{c = new Color(0,255,0);}
else if(name=="blue")
{c = new Color(0,0,255);}
}
else if(e.getSource()==SizeChoice)//画笔大小
{
String selected = SizeChoice.getSelectedItem();
if(selected=="1")
{
con = 1;
size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);
}
else if(selected=="3")
{
con = 3;
size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);
}
else if(selected=="5")
{con = 5;
size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);
}
else if(selected=="7")
{con = 7;
size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);
}
else if(selected=="9")
{con = 9;
size = new BasicStroke(con,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL);
}
}
else if(e.getSource()==EraserChoice)//橡皮大小
{
String Esize = EraserChoice.getSelectedItem();
if(Esize=="5")
{ Econ = 5*2; }
else if(Esize=="9")
{ Econ = 9*2; }
else if(Esize=="13")
{ Econ = 13*2; }
else if(Esize=="17")
{ Econ = 17*3; }
}
}
@SuppressWarnings({"serial","unused", "unchecked"})
public void mouseDragged(MouseEvent e)
{
Point p1 ;
switch(toolFlag){
case 0://画笔
x = (int)e.getX();
y = (int)e.getY();
p1 = new Point(x, y, c, toolFlag, con);
paintInfo.addElement(p1);
repaint();
break;
case 1://橡皮
x = (int)e.getX();
y = (int)e.getY();
p1 = new Point(x, y, null, toolFlag, Econ);
paintInfo.addElement(p1);
repaint();
break;
default :
}
}
public void mouseMoved(MouseEvent e) {}
public void update(Graphics g)
{
paint(g);
}
@SuppressWarnings("unchecked")
public void mousePressed(MouseEvent e)
{
Point p2;
switch(toolFlag){
case 3://直线
x = (int)e.getX();
y = (int)e.getY();
p2 = new Point(x, y, c, toolFlag, con);
paintInfo.addElement(p2);
break;
case 4: //圆
x = (int)e.getX();
y = (int)e.getY();
p2 = new Point(x, y, c, toolFlag, con);
paintInfo.addElement(p2);
break;
case 5: //矩形
x = (int)e.getX();
y = (int)e.getY();
p2 = new Point(x, y, c, toolFlag, con);
paintInfo.addElement(p2);
break;
default :
}
}
@SuppressWarnings("unchecked")
public void mouseReleased(MouseEvent e)
{
Point p3;
switch(toolFlag){
case 0://画笔
paintInfo.addElement(cutflag);
break;
case 1: //eraser
paintInfo.addElement(cutflag);
break;
case 3://直线
x = (int)e.getX();
y = (int)e.getY();
p3 = new Point(x, y, c, toolFlag, con);
paintInfo.addElement(p3);
paintInfo.addElement(cutflag);
repaint();
break;
case 4: //圆
x = (int)e.getX();
y = (int)e.getY();
p3 = new Point(x, y, c, toolFlag, con);
paintInfo.addElement(p3);
paintInfo.addElement(cutflag);
repaint();
break;
case 5: //矩形
x = (int)e.getX();
y = (int)e.getY();
p3 = new Point(x, y, c, toolFlag, con);
paintInfo.addElement(p3);
paintInfo.addElement(cutflag);
repaint();
break;
default:
}
}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==pen)//画笔
{toolFlag = 0;}
if(e.getSource()==eraser)//橡皮
{toolFlag = 1;}
if(e.getSource()==clear)//清除
{
toolFlag = 2;
paintInfo.removeAllElements();
repaint();
}
if(e.getSource()==drLine)//画线
{toolFlag = 3;}
if(e.getSource()==drCircle)//画圆
{toolFlag = 4;}
if(e.getSource()==drRect)//画矩形
{toolFlag = 5;}
if(e.getSource()==colchooser)//调色板
{
Color newColor = JColorChooser.showDialog(this,"调色板",c);
c = newColor;
}
}
}
//end paintboard
public class T{
public static void main(String args[]){
new paintboard("画图程序"); }
}
运行结果:
屠顾固泰: 首先基本的程序语法熟练掌握.清楚基本的数据结构,数组,哈希表,对OO思想有着很深的认识.了解或掌握几种常用的设计模式,单例、工厂,适配器、装饰器……对框架...
玉田县17021081351: 一个java程序能运行的条件? - ?
屠顾固泰: 1. 本机装了JRE2. java程序正确且其中有一个标准的main函数.两个条件足矣.满意请采纳!
玉田县17021081351: java编程至少需要学习到什么程度就可以应对一般的程序? - ?
屠顾固泰: 要能做到编出好的网络程序来,可不只要学习java语言基础,后面的网页(包括:html,servlet, jsp),数据库(mysql,sqlserver,oracal),框架(struts2,hibernate,spring)也要学好.这些都是由容易到难,当然还包括javascript,css样式,linux系统,tomcat容器这些小的部分.最重要的就是Java语言基础要打好,不然后面很难学,学好了后面就比较容易.最重要的就是Java基础,面试基础考的最多!
玉田县17021081351: 【04 - 25水帖】怎样才能成为一个合格的Java程序师??
屠顾固泰: 都是先上课,实践一些,然后在考试,考试过了就可以有证书了呀,呵呵,我觉得证书的考取是比较没有那么重要的,主要是学到的东西怎么样,要在校期间充实自己,然后在上班期间才能手到擒来,呵呵,我有朋友在中#关#村校区的,可以去看看
玉田县17021081351: 请自己编写任意一个JAVA程序,要求如下: (1)包括类、子类、继承、创建对象、设立属性、构建函数等基本 - ?
屠顾固泰: class Animal{ int age;//属性 } class dog extends Animal{ //继承 String name; public dog(String name)//构造方法 {this.name=name; } } public class Test { public static void main(String args[]){ Dog d=new Dog("小黄");//建立对象 d.age=15; //从Animal继承过来的属性.属性赋值 System.out.println(d.name+"的年纪是:"+d.age); } }
玉田县17021081351: 请用Java语言来编写一段程序,要求达到如下要求!(请高手给我源代码) - ?
屠顾固泰: import java.util.Scanner; public class Sort{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入第一个字符:"); String str1 = sc.next(); System.out.println("请输入第二个字符:"); ...
玉田县17021081351: java需要哪些条件才可以生成可执行文件?
屠顾固泰: 1 工程导出JAR包2下载 JAR转EXE工具
玉田县17021081351: 想当一名JAVA程序员,需要具备什么样的条件.知识需要达到何种水平? - ?
屠顾固泰: 你的情况和我差不多,可我已经投入工作了,我大一时和你的想法很想,我也很迷茫,那是就在想,我毕业了到底能做什么那,我的大学路应该怎么走才能让我在毕业后就会脱颖而出.我当时也问过很多人,查过很多资料,其实也没什么,现在...
玉田县17021081351: Java程序要求:?
屠顾固泰:package com.zhxin.test; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class test { public static void main(String[] args) { File file = new File("C:\\Users\\zhxin\\Desktop\\...
玉田县17021081351: java简单概念 - ?
屠顾固泰: Java是由Sun Microsystems公司于1995年5月推出的Java程序设计语言(以下简称Java语言)和Java平台的总称.用Java实现的HotJava浏览器(支持Java applet)显示了Java的魅力:跨平台、动态的Web、Internet计算.从此,Java被广泛接受...