几个小问题,麻烦大家讲解
一,如何才能控制组件在窗体的位置 二.如何动态建立对象,比如,我点一下就建立一个对象是怎么做到的?
三,如何设置组件大小?
四,如何画两条直线 ?(我只能画一条直线)
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
public class a extends Applet implements MouseMotionListener,MouseListener
{
float x1,y1,x2,y2;
public void init()
{
this.addMouseListener(this);
this.addMouseMotionListener(this);
}
public void paint(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
g2.draw(new Line2D.Float(x1,y1,x2,y2));
}
public void mousePressed(MouseEvent e)
{
x1=e.getX();
y1=e.getY();
}
public void mouseDragged(MouseEvent e)
{
x2=e.getX();
y2=e.getY();
repaint();
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void mouseMoved(MouseEvent e){}
}
这是程序,请大家指教一下
谢谢