import
java.awt.*;
import
java.awt.event.*;
import
javax.swing.*;
public
class
Peach
extends
JPanel{
public
void
paintComponent(Graphics g){ →設置圖形(內置)
super.paintComponent(g);
this.setBackground(Color.WHITE);
g.setColor(Color.BLUE);
→第一個矩形
g.fillRect(25,
25, 100, 30); →x和y
寬度和高度
g.setColor(new
Color(190,81,215)); →第二個矩形
g.fillRect(25,
65, 100, 30);
g.setColor(Color.RED);
→可以繪製文字
g.drawString("This
is some Text",
25, 120);
}
}
import
javax.swing.*;
public
class
bucky {
public
static
void
main(String[] args){
JFrame
f = new
JFrame("Title");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Peach
p = new
Peach();
f.add(p);
f.setSize(400,250);
f.setVisible(true);
}
}

沒有留言:
張貼留言