本文目錄一覽:
在用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); }
*/
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/255156.html