试试下面的程序,draw函数中注释掉的2行是用Graphics2D画,未注释的是用Graphics来画。
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JPanel;
public class Test extends JApplet {
private JPanel buttonPanel = new JPanel();
private JButton button = new JButton("Click");
private JPanel panel = new JPanel();
private JPanel graphicsPanel = new JPanel();
public Test() throws HeadlessException {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Graphics g = graphicsPanel.getGraphics();
draw(g);
}
});
}
public void init() {
buttonPanel.add(button);
panel.add(buttonPanel);
graphicsPanel.setPreferredSize(new Dimension(100, 100));
panel.add(graphicsPanel);
this.setContentPane(panel);
}
private void draw(Graphics g) {
g.drawArc(50, 50, 30, 30, 0, 360);
//Graphics2D g2 = (Graphics2D)g;
//g2.draw(new Ellipse2D.Double(50, 50, 30, 30));
}
}
???
你说的不详细
我不是很明白
◆◆
评论读取中....
请登录后再发表评论!
◆◆
修改失败,请稍后尝试