用*号打印的生日蛋糕或玫瑰百合?
创新互联建站作为成都网站建设公司,专注成都网站建设、网站设计,有关成都定制网站方案、改版、费用等问题,行业涉及服务器租用等多个领域,已为上千家企业服务,得到了客户的尊重与认可。
。。。。println("* * ****");
就这样打出来??
应该先调用父类的paint,即super.paint(g),不过最好的方法还是继承出一个JPanel的子类,然后重载它的paint方法,然后把这个子类的实例增加到JFrame的容器里
帮你改了一下。
你要画在panel上,然后frame.add(panel)就能显示。
是不是和applet搞混了,applet复写一些方法就能显示,但现在你编的是java gui
import java.awt.*;
import java.awt.Event.*;
import javax.swing.*; //import javax.swing.Timer;
import java.awt.BasicStroke;
//import java.util.Date;
//import java.text.*;
//import java.util.*;
public class TestGui {
public void paint(Graphics g) {
Graphics2D a2d = (Graphics2D) g;
int x = 120, y = 90, width = 150, height = 150;
a2d.setColor(Color.red);
a2d.setStroke(new BasicStroke(3.0f)); // 设置线条宽度,3.0即线的宽度
a2d.drawOval(x, y, width, height);
}
public static void main(String[] args) {
JFrame frame = new JFrame();
// frame.add(new paint(),BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setLocation(200, 200);
frame.setVisible(true);
Panel p = new Panel();
frame.add(p);
// frame.paint(null);
// TODO code application logic here
}
}
class Panel extends JPanel {
// 重新覆盖paint方法
public void paint(Graphics g) {
super.paint(g);
Graphics2D a2d = (Graphics2D) g;
int x = 120, y = 90, width = 150, height = 150;
a2d.setColor(Color.red);
a2d.setStroke(new BasicStroke(3.0f)); // 设置线条宽度,3.0即线的宽度
a2d.drawOval(x, y, width, height);
}
}
最大化图形消失的问题也解决了,注意类名首字母大写
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class Map {
public static void main(String[] args) {
new Draw();
}
}
class Draw extends JFrame{
ArrayListPoint points = new ArrayListPoint();
JPanel p=new JPanel();
Draw(){
add(p,BorderLayout.CENTER);
p.addMouseListener(new MyMouse());
this.addWindowStateListener(new MyWindow());
this.setResizable(true);
validate();
setBounds(50,50,500,400);
setVisible(true);
}
public void paint (Graphics g){
for(int i = 0;ipoints.size();i++){
g.fillOval(points.get(i).x, points.get(i).y, 30, 30);
}
}
private class MyWindow implements WindowStateListener{
public void windowStateChanged(WindowEvent arg0) {
repaint();
}
}
private class MyMouse extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
points.add(e.getPoint());
repaint();
}
}
}
. 所以只好求助你们的帮忙了 . 谢谢 .. 帮我翻译下吧 . 好麼? Vivian 按照翻译惯例,名字是作为代码使用的,不会按照字面意思翻译的,只能,tIfixW