import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Panel;
class punkt extends Panel
{
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.RED);
g.drawLine(50, 50, 51, 51);
}
}
class FrameDemo extends Frame
{
public FrameDemo(String title)
{
super(title);
}
public void init() {
this.setSize(700,700);
this.setBackground(Color.GREEN);
this.setBounds(100,100,300,300);
this.setLayout(null);
Panel panel = new Panel();
panel.setLayout(null);
panel.setBackground(Color.blue);
panel.setBounds(10,0,200,200);
this.add(panel);
this.add(new punkt());
this.setVisible(true);
}
}
class DrawPunkt
{
public static void main(String[] args)
{
new FrameDemo("FrameDemo");
}
}
求大神修改以下我的程序,我现在连点都没有。 下连接在一起面是我写的一个和没有和awt放在一起的点的移动的库,求大神指点
class punkt
{
private int x,y;
punkt()
}
punkt (int x , int y)
{
this.x =x;
this.y =y;
}
punkt(punkt p)
{
p.x = 10;
p.y = 20;
}
public int getX() {
return x;
}
public void setX(int x) {
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
// void setlocation....
void print(int x, int y)
{
System.out.println();
System.out.println("die Koordinate ist (" +x+","+y+ ")");
}
void setLocation(int x, int y)
{
this.x = x;
this.y = y;
String a = this.toString(this.x,this.y);
System.out.print("Die Koordinate ist (");
for( int i=0;i<a.length();i++ )
{
System.out.print( a.charAt(i) );
}
System.out.print(")");
}
// String toString
public String toString(int A, int B)
String a = String.valueOf(A);
String b = String.valueOf(B);
String s = a+","+b;
return s;
}
// void translate(int dx, int dy)
void translate(int dx, int dy)
{
this.x=this.x + dx;
this.y=this.y + dx;
this.print(this.x, this.y);
}
}
public class Uebung5 {
public static void main(String[] args) {
punkt p = new punkt();
p = new punkt(20,30);
p.setLocation(100,200);
p.translate(-20,+30);
// TODO Auto-generated method stub
}
}