用*號(hào)打印的生日蛋糕或玫瑰百合?
創(chuàng)新互聯(lián)建站作為成都網(wǎng)站建設(shè)公司,專(zhuān)注成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì),有關(guān)成都定制網(wǎng)站方案、改版、費(fèi)用等問(wèn)題,行業(yè)涉及服務(wù)器租用等多個(gè)領(lǐng)域,已為上千家企業(yè)服務(wù),得到了客戶(hù)的尊重與認(rèn)可。
。。。。println("* * ****");
就這樣打出來(lái)??
應(yīng)該先調(diào)用父類(lèi)的paint,即super.paint(g),不過(guò)最好的方法還是繼承出一個(gè)JPanel的子類(lèi),然后重載它的paint方法,然后把這個(gè)子類(lèi)的實(shí)例增加到JFrame的容器里
幫你改了一下。
你要畫(huà)在panel上,然后frame.add(panel)就能顯示。
是不是和applet搞混了,applet復(fù)寫(xiě)一些方法就能顯示,但現(xiàn)在你編的是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)); // 設(shè)置線(xiàn)條寬度,3.0即線(xiàn)的寬度
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)); // 設(shè)置線(xiàn)條寬度,3.0即線(xiàn)的寬度
a2d.drawOval(x, y, width, height);
}
}
最大化圖形消失的問(wèn)題也解決了,注意類(lèi)名首字母大寫(xiě)
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 按照翻譯慣例,名字是作為代碼使用的,不會(huì)按照字面意思翻譯的,只能,tIfixW