3个回答
推荐于2018-04-20
展开全部
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
class MyLine
{
private int x1,x2,y1,y2;
public MyLine(int x1,int x2,int y1,int y2)
{
this.x1=x1;
this.x2=x2;
this.y1=y1;
this.y2=y2;
}
public void drawMe(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
g.drawString("起始坐标:"+new String(x1+","+y1),x1,y1);
}
}
public class DrawLine extends Frame
{
Vector v=new Vector();
public static void main(String[]args)
{
DrawLine dl=new DrawLine();
dl.init();
}
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
Enumeration en=v.elements();
while(en.hasMoreElements())
{
MyLine m=(MyLine)en.nextElement();
m.drawMe(g);
}
}
public void init()
{
setSize(300,300);
setVisible(true);
addMouseListener(new MouseAdapter()
{
int x1,x2,y1,y2;
public void mousePressed(MouseEvent e)
{
x1=e.getX();
y1=e.getY();
}
public void mouseReleased(MouseEvent e)
{
x2=e.getX();
y2=e.getY();
Graphics g=e.getComponent().getGraphics();
g.setColor(Color.BLUE);
g.drawLine(x1,y1,x2,y2);
g.drawString(new String("起始点坐标:"+x1+","+y1),x1,y1);
v.add(new MyLine(x1,x2,y1,y2)); // here pay attention
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
((Window)e.getSource()).dispose();
System.exit(0);
}}
);
}
}
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
class MyLine
{
private int x1,x2,y1,y2;
public MyLine(int x1,int x2,int y1,int y2)
{
this.x1=x1;
this.x2=x2;
this.y1=y1;
this.y2=y2;
}
public void drawMe(Graphics g)
{
g.drawLine(x1,y1,x2,y2);
g.drawString("起始坐标:"+new String(x1+","+y1),x1,y1);
}
}
public class DrawLine extends Frame
{
Vector v=new Vector();
public static void main(String[]args)
{
DrawLine dl=new DrawLine();
dl.init();
}
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
Enumeration en=v.elements();
while(en.hasMoreElements())
{
MyLine m=(MyLine)en.nextElement();
m.drawMe(g);
}
}
public void init()
{
setSize(300,300);
setVisible(true);
addMouseListener(new MouseAdapter()
{
int x1,x2,y1,y2;
public void mousePressed(MouseEvent e)
{
x1=e.getX();
y1=e.getY();
}
public void mouseReleased(MouseEvent e)
{
x2=e.getX();
y2=e.getY();
Graphics g=e.getComponent().getGraphics();
g.setColor(Color.BLUE);
g.drawLine(x1,y1,x2,y2);
g.drawString(new String("起始点坐标:"+x1+","+y1),x1,y1);
v.add(new MyLine(x1,x2,y1,y2)); // here pay attention
}
});
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
((Window)e.getSource()).dispose();
System.exit(0);
}}
);
}
}
2013-11-07
展开全部
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
int x1,y1,x2,y2;
public Test(){
setVisible(true);
setSize(300,300) ;
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0) ; }});
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e){
x1=e.getX();
y1=e.getY();} });
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e){
x2=e.getX() ;y2=e.getY() ; repaint();
}});}
public void paint(Graphics g){
g.drawLine(x1,y1,x2,y2);
x1=x2;
y1=y2;
}
public static void main(String args[]){
new Test();}}
程序只能实现鼠标画线方面的功能!其他方面有待实现.
import java.awt.event.*;
import javax.swing.*;
public class Test extends JFrame {
int x1,y1,x2,y2;
public Test(){
setVisible(true);
setSize(300,300) ;
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0) ; }});
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e){
x1=e.getX();
y1=e.getY();} });
addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent e){
x2=e.getX() ;y2=e.getY() ; repaint();
}});}
public void paint(Graphics g){
g.drawLine(x1,y1,x2,y2);
x1=x2;
y1=y2;
}
public static void main(String args[]){
new Test();}}
程序只能实现鼠标画线方面的功能!其他方面有待实现.
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-11-07
展开全部
import java.applet.Applet;
import java.awt.*;
public class draw extends Applet
{
public void paint(Graphics g)
{
drawshape MyDS = new drawshape(size().width, size().height);
MyDS.paint(g);
}
class drawshape
{
private int x, y;
public void paint(Graphics g)
{
int posxs[] ={ x / 4, x / 2, x * 3 / 4, x * 7 / 8 };
int posys[] ={ y * 3 / 4, y - 10, y * 3 / 4, y * 7 / 8 };
g.drawString("直线", x / 8, y / 8);
g.drawString("一般矩形", x * 3 / 8, y / 8);
g.drawString("圆角矩形", x * 5 / 8, y / 8);
g.drawString("立体矩形", 20, y / 4 + 30);
g.drawString("填充矩形", x *1/4 + 20, y / 4 + 30);
g.drawString("椭圆", x / 2 + 40, y / 4 + 30);
g.drawString("圆弧", 20, y * 7 / 8);
g.drawString("多边形", x / 4 + 10, y * 7 / 8);
g.setColor(Color.red);
g.drawLine(10, 10, x / 4, y / 4);
g.setColor(Color.blue);
g.drawRect(x / 4 + 10, 10, x / 4, y / 4);
g.setColor(Color.black);
g.drawRoundRect(x / 2 + 30, 10, x / 4, y / 4, x / 8, y / 8);
g.setColor(Color.blue);
g.fill3DRect(10, y / 4 + 40, x / 4, y / 4, false);
g.setColor(Color.yellow);
g.fillRect(x / 4 + 20, y / 4 + 40, x / 4, y / 4);
g.setColor(Color.red);
g.fillOval(x / 2 + 40, y / 4 + 40, x / 4, y / 4);
g.setColor(Color.blue);
g.drawArc(10, y * 3 / 4, x / 4, y / 4, 90, 180);
g.setColor(Color.blue);
g.fillPolygon(posxs, posys, posxs.length);
}
drawshape(int winx, int winy)
{
x = winx;
y = winy;
}
}
}
import java.awt.*;
public class draw extends Applet
{
public void paint(Graphics g)
{
drawshape MyDS = new drawshape(size().width, size().height);
MyDS.paint(g);
}
class drawshape
{
private int x, y;
public void paint(Graphics g)
{
int posxs[] ={ x / 4, x / 2, x * 3 / 4, x * 7 / 8 };
int posys[] ={ y * 3 / 4, y - 10, y * 3 / 4, y * 7 / 8 };
g.drawString("直线", x / 8, y / 8);
g.drawString("一般矩形", x * 3 / 8, y / 8);
g.drawString("圆角矩形", x * 5 / 8, y / 8);
g.drawString("立体矩形", 20, y / 4 + 30);
g.drawString("填充矩形", x *1/4 + 20, y / 4 + 30);
g.drawString("椭圆", x / 2 + 40, y / 4 + 30);
g.drawString("圆弧", 20, y * 7 / 8);
g.drawString("多边形", x / 4 + 10, y * 7 / 8);
g.setColor(Color.red);
g.drawLine(10, 10, x / 4, y / 4);
g.setColor(Color.blue);
g.drawRect(x / 4 + 10, 10, x / 4, y / 4);
g.setColor(Color.black);
g.drawRoundRect(x / 2 + 30, 10, x / 4, y / 4, x / 8, y / 8);
g.setColor(Color.blue);
g.fill3DRect(10, y / 4 + 40, x / 4, y / 4, false);
g.setColor(Color.yellow);
g.fillRect(x / 4 + 20, y / 4 + 40, x / 4, y / 4);
g.setColor(Color.red);
g.fillOval(x / 2 + 40, y / 4 + 40, x / 4, y / 4);
g.setColor(Color.blue);
g.drawArc(10, y * 3 / 4, x / 4, y / 4, 90, 180);
g.setColor(Color.blue);
g.fillPolygon(posxs, posys, posxs.length);
}
drawshape(int winx, int winy)
{
x = winx;
y = winy;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询