您的位置:

java大作业完成一个绘图软件(用java画图)

本文目录一览:

在用Java做画图软件,画完时想在图形处添加文本框以输入文字,怎么搞?

LZ知道验证码不?

一样的道理,接收用户输入的内容,传给图像构造类,然后输出在客户端就可以了,一样的!

怎么可能在图片里面给个文本框让用户输入呢?开玩笑呢!!

JAVA绘图软件

html

head

body

table width="600" height="400" cellpadding="0" cellspacing="0" border="1" bordercolordark="#000000" id="table" style="font-size:16px; color: #000000;font-weight:bold;"

script

function GetALine( )

{

var fso, f, s;

s = "";

fso = new ActiveXObject("Scripting.FileSystemObject");

f = fso.OpenTextFile('d:\\info.txt', 1, false);

var ss=[]

while (!f.AtEndOfStream){

ms= f.ReadLine( ).match(/name:([^|]+)\|phone:(.+)/);

document.write(

'trtd ',ms[1] ,'/tdtd width="259" ',ms[2],'/td/tr'

);

}

f.Close( );

}

GetALine();

/script

/table

/head

/html

java 绘图程序

我基于你原来画图的方法,添加了事件触发的命令b[j].setActionCommand("b" + j);否则你不能在事件响应处理的方法中使用e.getActionCommand(),而且字符串的比较用equals方法比较好。现在可以运行了,你可以看一下:

import java.applet.Applet;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class drawing extends Applet implements ActionListener {

Button b[] = new Button[5];

String fontname = "仿宋_GB2312";

int style = Font.PLAIN;

int size = 24;

int index = 0;

Font myfont;

public void init() {

setSize(700,700);

myfont = new Font(fontname, style, size);

b[0] = new Button("扇形");

b[1] = new Button("圆形");

b[2] = new Button("三角形");

b[3] = new Button("长方形");

b[4] = new Button("椭圆形");

for (int j = 0; j b.length; j++) {

b[j].setBounds(10, 10, 50, 20);

b[j].addActionListener(this);

b[j].setActionCommand("b" + j);

add(b[j]);

}

}

public void actionPerformed(ActionEvent e) {

if (e.getActionCommand().equals("b0")) {

index = 0;

repaint();

}

if (e.getActionCommand().equals("b1")) {

index = 1;

repaint();

}

if (e.getActionCommand().equals("b2")) {

index = 2;

repaint();

}

if (e.getActionCommand().equals("b3")) {

index = 3;

repaint();

}

if (e.getActionCommand().equals("b4")) {

index = 4;

repaint();

}

}

public void paint(Graphics g) {

switch (index) {

case 0:

g.fillArc(0, 60, 80, 60, 30, 120);

break;

case 1:

g.drawOval( 300, 50, 60, 60);

break;

case 2:

Polygon filledPolygon = new Polygon();

filledPolygon.addPoint(380, 50);

filledPolygon.addPoint(380, 110);

filledPolygon.addPoint(450, 90);

g.drawPolygon(filledPolygon);

break;

case 3:

g.drawRect( 200, 50, 80, 60);

break;

case 4:

g.drawOval(100, 50, 80, 60);

break;

default:

g.fillArc(0, 60, 80, 60, 30, 120);

break;

}

}

/*

* public void paint(Graphics g) { g.fillArc( 0, 60, 80, 60, 30, 120);

* //绘制扇形 g.drawOval( 100, 50, 80, 60); g.drawRect( 200, 50, 80, 60);

* g.drawOval( 300, 50, 60, 60); Polygon filledPolygon=new Polygon();

* filledPolygon.addPoint(380,50); filledPolygon.addPoint(380,110);

* filledPolygon.addPoint(450,90); g.drawPolygon(filledPolygon); }

*/

}