首先,如果你只是要实现电子时钟,根本就不需要用到多线程。
如果你真的是要使用,就新建一个类,实现Runnable接口就是了。
如:
class MyThread1 implements Runnable{
public MyThread(){
}
public void run(){
}
}
使用的时候,就:
Thread myThread=new Thread(new MyThread());
myThreadstart();
如果要画图,你就直接把组件通过构造方法传到MyThread中就是了
package math;
import javaawtBorderLayout;
import javaawtDimension;
import javaawtGridLayout;
import javaawtToolkit;
import javaxswingButtonGroup;
import javaxswingJButton;
import javaxswingJComboBox;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJPanel;
import javaxswingJRadioButton;
import javaxswingJTextField;
public class UI extends JFrame
{
MyPanel mp;
JPanel pl = new JPanel();
JPanel pl1 = new JPanel(),
pl2 = new JPanel(),
pl3 = new JPanel(),
pl4 = new JPanel();
JRadioButton rb1,rb2;
ButtonGroup bg = new ButtonGroup();
JTextField tf = new JTextField(16);
String[] s = {"y = sin(x)", "y = cos(x)", "y = tan(x)",
"y = pow(x, 2)", "y = pow(x, 3)", "y = log(x)",
"y = pow(2, x)", "y = sqrt(x)", "r = a(sita)"};
JComboBox cb;
JButton bn1 = new JButton("变宽"),
bn2 = new JButton("变窄"),
bn3 = new JButton("拉长"),
bn4 = new JButton("压短"),
bn = new JButton("绘图"),
exit = new JButton("退出"),
bn5 = new JButton("左移"),
bn6 = new JButton("右移"),
bn7 = new JButton("上移"),
bn8 = new JButton("下移");
public UI()
{
mp = new MyPanel(this);
pl1setLayout(new GridLayout(1, 2));
pl2setLayout(new GridLayout(1, 2));
pl3setLayout(new GridLayout(1, 2));
pl4setLayout(new GridLayout(1, 2));
pl1add(bn1); bn1setEnabled(false);
pl1add(bn2); bn2setEnabled(false);
pl2add(bn3); bn3setEnabled(false);
pl2add(bn4); bn4setEnabled(false);
pl3add(bn5); bn5setEnabled(false);
pl3add(bn6); bn6setEnabled(false);
pl4add(bn7); bn7setEnabled(false);
pl4add(bn8); bn8setEnabled(false);
plsetLayout(new GridLayout(20, 1));
rb1 = new JRadioButton("输入函数");
rb2 = new JRadioButton("选择已有函数");
rb2setSelected(true);
tfsetEnabled(false);
bgadd(rb1); bgadd(rb2);
rb1addActionListener(mp);
rb2addActionListener(mp);
pladd(rb1);
pladd(tf);
pladd(rb2);
cb = new JComboBox(s);
pladd(cb);
pladd(new JLabel());
pladd(pl1); pladd(pl2);
pladd(pl3); pladd(pl4);
pladd(bn);
pladd(exit);
bn1addActionListener(mp);
bn2addActionListener(mp);
bn3addActionListener(mp);
bn4addActionListener(mp);
bn5addActionListener(mp);
bn6addActionListener(mp);
bn7addActionListener(mp);
bn8addActionListener(mp);
bnaddActionListener(mp);
exitaddActionListener(mp);
thissetLayout(new BorderLayout());
thisadd(mp, BorderLayoutCENTER);
thisadd(pl, BorderLayoutEAST);
thissetTitle("平面直角坐标系画图小工具");
thissetSize(797, 600 + 37);
Dimension dn = ToolkitgetDefaultToolkit()getScreenSize();
thissetLocation((dnwidth - 797) / 2, (dnheight - 637) / 2);
thissetVisible(true);
thissetDefaultCloseOperation(3);
}
public static void main(String[] args)
{
new UI();
}
}
package math;
import javaawtColor;
import javaawtGraphics;
import javaawtGraphics2D;
import javaawtPoint;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaawteventMouseEvent;
import javaawteventMouseMotionListener;
import javaawtgeomEllipse2D;
import javaawtgeomLine2D;
import javaxswingJOptionPane;
import javaxswingJPanel;
public class MyPanel extends JPanel implements ActionListener,MouseMotionListener
{
UI ui;
int flag;
double h_times;
int w_times;
int dx;
int dy;
String str;
Point pt = new Point(0, 0);
void init()
{
flag = -1;
h_times = MathPI / 100;
w_times = 100;
dx = 300;
dy = 300;
}
public MyPanel(UI ui)
{
thisaddMouseMotionListener(this);
init();
thisui = ui;
}
public void paintComponent(Graphics g)
{
superpaintComponent(g);
Graphics2D g2 = (Graphics2D)g;
drawCoordinate(g2);
Line2D line;
g2setColor(ColorBLUE);
g2drawString("(" + (ptx - 300) + ", " + (300 - pty) + ")", ptx + 20, pty + 20);
switch(flag)
{
case 0:
g2drawString("y = Asin(Bx + C) + D", 105, 60);
for(double i = 0; i < 600; i += 001)
{
line = new Line2DDouble(i, dy - Mathsin(getReal_X(i)) w_times, i + 1, dy - Mathsin(getReal_X(i + 1)) w_times);
g2draw(line);
}
break;
case 1:
g2drawString("y = Acos(Bx + C) + D", 105, 60);
for(double i = 0; i < 600; i += 001)
{
line = new Line2DDouble(i, dy - Mathcos(getReal_X(i)) w_times, i + 1, dy - Mathcos(getReal_X(i + 1)) w_times);
g2draw(line);
}
break;
case 2:
g2drawString("y = Atan(Bx + C) + D", 105, 60);
for(double i = 0; i < 600; i += 001)
{
line = new Line2DDouble(i, dy - Mathtan(getReal_X(i)) w_times, i + 1, dy - Mathtan(getReal_X(i + 1)) w_times);
g2draw(line);
}
break;
case 3:
g2drawString("y = Apow(Bx + C, 2) + D", 105, 60);
for(double i = 0; i < 600; i += 001)
{
line = new Line2DDouble(i, dy - Mathpow(getReal_X(i), 2) w_times, i + 1, dy - Mathpow(getReal_X(i + 1), 2) w_times);
g2draw(line);
}
break;
case 4:
g2drawString("y = Apow(Bx + C, 3) + D", 105, 60);
for(double i = 0; i < 600; i += 001)
{
line = new Line2DDouble(i, dy - Mathpow(getReal_X(i), 3) w_times, i + 1, dy - Mathpow(getReal_X(i + 1), 3) w_times);
g2draw(line);
}
break;
case 5:
g2drawString("y = Alog(Bx + C) + D", 105, 60);
for(double i = 0; i < 600; i += 001)
{
line = new Line2DDouble(i, dy - Mathlog(getReal_X(i)) w_times, i + 1, dy - Mathlog(getReal_X(i + 1)) w_times);
g2draw(line);
}
break;
case 6:
g2drawString("y = Apow(2, Bx + C) + D", 105, 60);
for(double i = 0; i < 600; i += 001)
{
line = new Line2DDouble(i, dy - Mathpow(2, getReal_X(i)) w_times, i + 1, dy - Mathpow(2, getReal_X(i + 1)) w_times);
g2draw(line);
}
break;
case 7:
g2drawString("y = Asqrt(Bx + C) + D", 105, 60);
for(double i = 0; i < 600; i += 001)
{
line = new Line2DDouble(i, dy - Mathsqrt(getReal_X(i)) w_times, i + 1, dy - Mathsqrt(getReal_X(i + 1)) w_times);
g2draw(line);
}
break;
case 8:
g2drawString("y = a(sita)", 105, 60);
for(double i = 0; i < 600; i += 001)
{
line = new Line2DDouble(getReal_X(i) Mathcos(getReal_X(i)), dy - getReal_X(i) Mathsin(getReal_X(i)) w_times, getReal_X(i) Mathcos(getReal_X(i + 1)), dy - getReal_X(i) Mathsin(getReal_X(i + 1)) w_times);
g2draw(line);
}
break;
}
if(flag != -1)
{
g2drawString("A = " + w_times, 105, 90);
g2drawString("B= " + h_times, 105, 120);
g2drawString("C= " + (300 - dx), 105, 150);
g2drawString("D= " + (300 - dy), 105, 180);
}
}
private double getReal_X(double x)
{
return (x - dx) h_times;
}
private void drawCoordinate(Graphics2D g2)
{
int len = 20;
Line2D line;
for(int i = 0; i <= 600 / len; i++)
{
g2setColor(ColorPINKdarker());
if(i == 300 / len)
g2setColor(ColorRED);
else;
line = new Line2DDouble(0, i len, 600, i len);
g2draw(line);
line = new Line2DDouble(i len, 0, i len, 600);
g2draw(line);
}
drawPoint(g2, 300, 300);
}
private void drawPoint(Graphics2D g2, double x, double y)
{
g2setColor(ColorYELLOW);
Ellipse2D circle = new Ellipse2DDouble(x - 2, y - 2, 4, 4);
g2fill(circle);
}
public void actionPerformed(ActionEvent e)
{
if(egetSource() == uirb1)
{
uitfsetEnabled(true);
uicbsetEnabled(false);
flag = -1;
}
if(egetSource() == uirb2)
{
uitfsetEnabled(false);
uicbsetEnabled(true);
}
if(egetSource() == uibn1)
{
h_times /= 11;
}
if(egetSource() == uibn2)
{
h_times = 11;
}
if(egetSource() == uibn3)
{
// uibn4setEnabled(true);
w_times += 10;
// if(w_times >= 300)
// uibn3setEnabled(false);
}
if(egetSource() == uibn4)
{
// uibn3setEnabled(true);
w_times -= 10;
// if(w_times <= 0)
// uibn4setEnabled(false);
}
if(egetSource() == uibn5)
{
dx -= 10;
}
if(egetSource() == uibn6)
{
dx += 10;
}
if(egetSource() == uibn7)
{
// uibn8setEnabled(true);
dy -= 10;
// if(dy <= 0)
// uibn7setEnabled(false);
}
if(egetSource() == uibn8)
{
// uibn7setEnabled(true);
dy += 10;
// if(dy >= 600)
// uibn8setEnabled(false);
}
if(egetSource() == uibn)
{
if(uitfisEnabled() == true)
{
str = uitfgetText();
if(str == null || strlength() == 0)
{
uibn1setEnabled(false);
uibn2setEnabled(false);
uibn3setEnabled(false);
uibn4setEnabled(false);
uibn5setEnabled(false);
uibn6setEnabled(false);
uibn7setEnabled(false);
uibn8setEnabled(false);
JOptionPaneshowMessageDialog(this, "请输入函数表达式 !");
return;
}
}else flag = -2;
uibn1setEnabled(true);
uibn2setEnabled(true);
uibn3setEnabled(true);
uibn4setEnabled(true);
uibn5setEnabled(true);
uibn6setEnabled(true);
uibn7setEnabled(true);
uibn8setEnabled(true);
init();
if(uicbisEnabled() == true)
{
flag = uicbgetSelectedIndex();
}
}
if(egetSource() == uiexit)
Systemexit(0);
repaint();
}
public void mouseDragged(MouseEvent arg0)
{
}
public void mouseMoved(MouseEvent e)
{
pt = egetPoint();
repaint();
}
}
import javaapplet;
import javaawt;
import javaawtevent;
import javautil;
import javaxswing;
import javaawtgeom;
import javaio;
class Point implements Serializable
{
int x,y;
Color col;
int tool;
int boarder;
Point(int x, int y, Color col, int tool, int boarder)
{
thisx = x;
thisy = y;
thiscol = col;
thistool = tool;
thisboarder = boarder;
}
}
class paintboard extends Frame implements ActionListener,MouseMotionListener,MouseListener,ItemListener
{
int x = -1, y = -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,BasicStrokeCAP_BUTT,BasicStrokeJOIN_BEVEL);//画笔粗细
Point cutflag = new Point(-1, -1, c, 6, con);//截断标志
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;
paintboard(String s)
{
super(s);
addMouseMotionListener(this);
addMouseListener(this);
paintInfo = new Vector();
/各工具按钮及选择项/
//颜色选择
ColChoice = new Choice();
ColChoiceadd("black");
ColChoiceadd("red");
ColChoiceadd("blue");
ColChoiceadd("green");
ColChoiceaddItemListener(this);
//画笔大小选择
SizeChoice = new Choice();
SizeChoiceadd("1");
SizeChoiceadd("3");
SizeChoiceadd("5");
SizeChoiceadd("7");
SizeChoiceadd("9");
SizeChoiceaddItemListener(this);
//橡皮大小选择
EraserChoice = new Choice();
EraserChoiceadd("5");
EraserChoiceadd("9");
EraserChoiceadd("13");
EraserChoiceadd("17");
EraserChoiceaddItemListener(this);
////////////////////////////////////////////////////
toolPanel = new Panel();
clear = new Button("清除");
eraser = new Button("橡皮");
pen = new Button("画笔");
drLine = new Button("画直线");
drCircle = new Button("画圆形");
drRect = new Button("画矩形");
openPic = new Button("打开图画");
savePic = new Button("保存图画");
colchooser = new Button("显示调色板");
//各组件事件监听
clearaddActionListener(this);
eraseraddActionListener(this);
penaddActionListener(this);
drLineaddActionListener(this);
drCircleaddActionListener(this);
drRectaddActionListener(this);
openPicaddActionListener(this);
savePicaddActionListener(this);
colchooseraddActionListener(this);
颜色 = new Label("画笔颜色",LabelCENTER);
大小B = new Label("画笔大小",LabelCENTER);
大小E = new Label("橡皮大小",LabelCENTER);
//面板添加组件
toolPaneladd(openPic);
toolPaneladd(savePic);
toolPaneladd(pen);
toolPaneladd(drLine);
toolPaneladd(drCircle);
toolPaneladd(drRect);
toolPaneladd(颜色); toolPaneladd(ColChoice);
toolPaneladd(大小B); toolPaneladd(SizeChoice);
toolPaneladd(colchooser);
toolPaneladd(eraser);
toolPaneladd(大小E); toolPaneladd(EraserChoice);
toolPaneladd(clear);
//工具面板到APPLET面板
add(toolPanel,BorderLayoutNORTH);
setBounds(60,60,900,600); setVisible(true);
validate();
//dialog for save and load
openPicture = new FileDialog(this,"打开图画",FileDialogLOAD);
openPicturesetVisible(false);
savePicture = new FileDialog(this,"保存图画",FileDialogSAVE);
savePicturesetVisible(false);
openPictureaddWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ openPicturesetVisible(false); }
});
savePictureaddWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ savePicturesetVisible(false); }
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ Systemexit(0);}
});
}
public void paint(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
Point p1,p2;
n = paintInfosize();
if(toolFlag==2)
gclearRect(0,0,getSize()width,getSize()height);//清除
for(int i=0; i<n ;i++){
p1 = (Point)paintInfoelementAt(i);
p2 = (Point)paintInfoelementAt(i+1);
size = new BasicStroke(p1boarder,BasicStrokeCAP_BUTT,BasicStrokeJOIN_BEVEL);
g2dsetColor(p1col);
g2dsetStroke(size);
if(p1tool==p2tool)
{
switch(p1tool)
{
case 0://画笔
Line2D line1 = new Line2DDouble(p1x, p1y, p2x, p2y);
g2ddraw(line1);
break;
case 1://橡皮
gclearRect(p1x, p1y, p1boarder, p1boarder);
break;
case 3://画直线
Line2D line2 = new Line2DDouble(p1x, p1y, p2x, p2y);
g2ddraw(line2);
break;
case 4://画圆
Ellipse2D ellipse = new Ellipse2DDouble(p1x, p1y, Mathabs(p2x-p1x) , Mathabs(p2y-p1y));
g2ddraw(ellipse);
break;
case 5://画矩形
Rectangle2D rect = new Rectangle2DDouble(p1x, p1y, Mathabs(p2x-p1x) , Mathabs(p2y-p1y));
g2ddraw(rect);
break;
case 6://截断,跳过
i=i+1;
break;
default :
}//end switch
}//end if
}//end for
}
public void itemStateChanged(ItemEvent e)
{
if(egetSource()==ColChoice)//预选颜色
{
String name = ColChoicegetSelectedItem();
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(egetSource()==SizeChoice)//画笔大小
{
String selected = SizeChoicegetSelectedItem();
if(selected=="1")
{
con = 1;
size = new BasicStroke(con,BasicStrokeCAP_BUTT,BasicStrokeJOIN_BEVEL);
}
else if(selected=="3")
{
con = 3;
size = new BasicStroke(con,BasicStrokeCAP_BUTT,BasicStrokeJOIN_BEVEL);
}
else if(selected=="5")
{con = 5;
size = new BasicStroke(con,BasicStrokeCAP_BUTT,BasicStrokeJOIN_BEVEL);
}
else if(selected=="7")
{con = 7;
size = new BasicStroke(con,BasicStrokeCAP_BUTT,BasicStrokeJOIN_BEVEL);
}
else if(selected=="9")
{con = 9;
size = new BasicStroke(con,BasicStrokeCAP_BUTT,BasicStrokeJOIN_BEVEL);
}
}
else if(egetSource()==EraserChoice)//橡皮大小
{
String Esize = EraserChoicegetSelectedItem();
if(Esize=="5")
{ Econ = 52; }
else if(Esize=="9")
{ Econ = 92; }
else if(Esize=="13")
{ Econ = 132; }
else if(Esize=="17")
{ Econ = 173; }
}
}
public void mouseDragged(MouseEvent e)
{
Point p1 ;
switch(toolFlag){
case 0://画笔
x = (int)egetX();
y = (int)egetY();
p1 = new Point(x, y, c, toolFlag, con);
paintInfoaddElement(p1);
repaint();
break;
case 1://橡皮
x = (int)egetX();
y = (int)egetY();
p1 = new Point(x, y, null, toolFlag, Econ);
paintInfoaddElement(p1);
repaint();
break;
default :
}
}
public void mouseMoved(MouseEvent e) {}
public void update(Graphics g)
{
paint(g);
}
public void mousePressed(MouseEvent e)
{
Point p2;
switch(toolFlag){
case 3://直线
x = (int)egetX();
y = (int)egetY();
p2 = new Point(x, y, c, toolFlag, con);
paintInfoaddElement(p2);
break;
case 4: //圆
x = (int)egetX();
y = (int)egetY();
p2 = new Point(x, y, c, toolFlag, con);
paintInfoaddElement(p2);
break;
case 5: //矩形
x = (int)egetX();
y = (int)egetY();
p2 = new Point(x, y, c, toolFlag, con);
paintInfoaddElement(p2);
break;
default :
}
}
public void mouseReleased(MouseEvent e)
{
Point p3;
switch(toolFlag){
case 0://画笔
paintInfoaddElement(cutflag);
break;
case 1: //eraser
paintInfoaddElement(cutflag);
break;
case 3://直线
x = (int)egetX();
y = (int)egetY();
p3 = new Point(x, y, c, toolFlag, con);
paintInfoaddElement(p3);
paintInfoaddElement(cutflag);
repaint();
break;
case 4: //圆
x = (int)egetX();
y = (int)egetY();
p3 = new Point(x, y, c, toolFlag, con);
paintInfoaddElement(p3);
paintInfoaddElement(cutflag);
repaint();
break;
case 5: //矩形
x = (int)egetX();
y = (int)egetY();
p3 = new Point(x, y, c, toolFlag, con);
paintInfoaddElement(p3);
paintInfoaddElement(cutflag);
repaint();
break;
default:
}
}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void actionPerformed(ActionEvent e)
{
if(egetSource()==pen)//画笔
{toolFlag = 0;}
if(egetSource()==eraser)//橡皮
{toolFlag = 1;}
if(egetSource()==clear)//清除
{
toolFlag = 2;
paintInforemoveAllElements();
repaint();
}
if(egetSource()==drLine)//画线
{toolFlag = 3;}
if(egetSource()==drCircle)//画圆
{toolFlag = 4;}
if(egetSource()==drRect)//画矩形
{toolFlag = 5;}
if(egetSource()==colchooser)//调色板
{
Color newColor = JColorChoosershowDialog(this,"调色板",c);
c = newColor;
}
if(egetSource()==openPic)//打开图画
{
openPicturesetVisible(true);
if(openPicturegetFile()!=null)
{
int tempflag;
tempflag = toolFlag;
toolFlag = 2 ;
repaint();
try{
paintInforemoveAllElements();
File filein = new File(openPicturegetDirectory(),openPicturegetFile());
picIn = new FileInputStream(filein);
VIn = new ObjectInputStream(picIn);
paintInfo = (Vector)VInreadObject();
VInclose();
repaint();
toolFlag = tempflag;
}
catch(ClassNotFoundException IOe2)
{
repaint();
toolFlag = tempflag;
Systemoutprintln("can not read object");
}
catch(IOException IOe)
{
repaint();
toolFlag = tempflag;
Systemoutprintln("can not read file");
}
}
}
if(egetSource()==savePic)//保存图画
{
savePicturesetVisible(true);
try{
File fileout = new File(savePicturegetDirectory(),savePicturegetFile());
picOut = new FileOutputStream(fileout);
VOut = new ObjectOutputStream(picOut);
VOutwriteObject(paintInfo);
VOutclose();
}
catch(IOException IOe)
{
Systemoutprintln("can not write object");
}
}
}
}//end paintboard
public class pb
{
public static void main(String args[])
{ new paintboard("画图程序"); }
}
使用java画圆要用到绘图类Graphics,下面是实例代码和运行效果:
package comdikeademo01;
import javaawt;
import javaxswing;
// java绘图原理
public class demo_01 extends JFrame {
MyPanel mp = null;
public static void main(String[] args) {
// TODO 自动生成的方法存根
demo_01 demo01 = new demo_01();
}
public demo_01(){
mp = new MyPanel();
thisadd(mp);
thissetSize(400, 300);
thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
thissetVisible(true);
}
}
// 定义一个MyPanel面板,用于绘图区域
class MyPanel extends JPanel{
//覆盖JPanel
// Graphics 是绘图的重要类,可以理解成一支画笔
public void paint(Graphics g){
// 1 调用父类函数完成初始化任务
// 这句话不可以少
superpaint(g);
// 先画出一个圆圈
gdrawOval(100, 100, 30, 30);
}
}
代码复制进ide编程工具,运行效果如下:
只提指导,没有源码。
在 Java 中要自定义组件,一般是覆盖掉 protected void paintComponent(Graphics g); 方法就可以了,对于你这个类似画笔的程序,首先,整个画布是一个自定义的继承自像 JPanel 一样的东西,不过我们需要覆盖它的 paintComponent 方法,因为:一、我们需要在当鼠标拖放一个东西时我们移动这个选中的图形时记住它的位置;二、设定 label 时需要保存它的 Label。三、知道图形的形状。
,然后在 paintComponent 时依次画出各个图形来。
要绘图:
1、直线,gdrawLine(x,y,x2,y2); // 参数分别是起止点坐标。
2、矩形,gfillRect(x, y, w, h); // 参数分别是左上角坐标和宽及高。
3、椭圆,gfillOval(x, y, w, h); // 参数分别是椭圆形的外切矩形的左上角坐标及宽和高,当w 和 h 相等时是个圆。
准备绘图前 gsetColor() 设置前景色;先把整个画布用 gfillRect() 涂成白色,再分别画各个图形,最后绘制 Label 应该在画图形之后再做。
移动图形,是给 画布组件 addMouseMotionListener 来监听事件的,在拖动时先通过 mouseDragged 事件的 MouseEventpoint 知道它的位置是在哪个图形的内部,之后的移动就修改这个图形的位置。
以上就是关于java如何实现多线程绘图全部的内容,包括:java如何实现多线程绘图、怎么用java绘制函数图像、JAVA编译简易画图板代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)