/*
* ClassDemol.java
*
* Created on 2007年4月5日, 下午3:33
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/package hhh;import java.awt.Graphics;/**
*
* @author Administrator
*/
public class ClassDemol {
/** Creates a new instance of ClassDemol */
public ClassDemol() {
} private int x; private int y; private int width; private int height; public void init() {
width = 60;
height = 60;
} public void SetPosition(int xPos, int yPos) {
x=xPos;
y=yPos;
} public void paint(Graphics g) {
SetPosition(20,20);
g.drawRect(x,y,width,height);
g.drawString("1的位置"+x,20,100);
g.drawString("1的位置"+y,20,120);
g.drawRect(x,y,width,height);
g.drawString("2的位置"+x,170,100);
g.drawString("2的位置"+y,170,120);
}
}
/*
* Main.java
*
* Created on 2007年4月2日, 上午8:19
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/package hhh;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*; /**
*
* @author Administrator
*/
public class Main extends Frame{
/** Creates a new instance of Main */
public Main() {
super("drawOval Example");
setSize(200, 200);
show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Main m = new Main();
ClassDemol c = new ClassDemol();
c.init();
c.paint(m.getGraphics()); }
}
程序可以运行,但是矩形出不来,只出来窗体。
请大家告诉我,谢谢!
* ClassDemol.java
*
* Created on 2007年4月5日, 下午3:33
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/package hhh;import java.awt.Graphics;/**
*
* @author Administrator
*/
public class ClassDemol {
/** Creates a new instance of ClassDemol */
public ClassDemol() {
} private int x; private int y; private int width; private int height; public void init() {
width = 60;
height = 60;
} public void SetPosition(int xPos, int yPos) {
x=xPos;
y=yPos;
} public void paint(Graphics g) {
SetPosition(20,20);
g.drawRect(x,y,width,height);
g.drawString("1的位置"+x,20,100);
g.drawString("1的位置"+y,20,120);
g.drawRect(x,y,width,height);
g.drawString("2的位置"+x,170,100);
g.drawString("2的位置"+y,170,120);
}
}
/*
* Main.java
*
* Created on 2007年4月2日, 上午8:19
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/package hhh;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*; /**
*
* @author Administrator
*/
public class Main extends Frame{
/** Creates a new instance of Main */
public Main() {
super("drawOval Example");
setSize(200, 200);
show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Main m = new Main();
ClassDemol c = new ClassDemol();
c.init();
c.paint(m.getGraphics()); }
}
程序可以运行,但是矩形出不来,只出来窗体。
请大家告诉我,谢谢!
import java.awt.Panel;
class ClassDemo extends Panel {
public ClassDemo() {
} private int x; private int y; private int width; private int height; public void init() {
width = 60;
height = 60;
} public void SetPosition(int xPos, int yPos) {
x=xPos;
y=yPos;
} public void paint(Graphics g) {
SetPosition(20,20);
g.drawRect(x,y,width,height);
g.drawString("1µÄλÖÃ"+x,20,100);
g.drawString("1µÄλÖÃ"+y,20,120);
g.drawRect(x,y,width,height);
g.drawString("2µÄλÖÃ"+x,170,100);
g.drawString("2µÄλÖÃ"+y,170,120);
}
}
public class Main extends Frame{
public Main() {
super("drawOval Example");
setSize(200, 200);
show();
}
public static void main(String[] args) {
Main m = new Main(); ClassDemo c = new ClassDemo();
c.init();
m.add(c);
}
}帮你改了下,