大家好,我学Java不久,在学到图形接口的时候运行代码有些不明白的地方,请各高手指教,代码如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*; public class SimpleGui3C implements ActionListener {
JFrame frame;
public static void main (String[] args) {
SimpleGui3C gui = new SimpleGui3C();
gui.go();
}
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Change colors");
button.addActionListener(this);
MyDrawPanel One = new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.CENTER, One);
frame.setSize(300,300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
frame.repaint();
} class MyDrawPanel extends JPanel {
public void paintComponet(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
GradientPaint gradient = new GradientPaint(70,70,Color.blue,150,150,Color.orange);
g2d.setPaint(gradient);
g2d.fillOval(70,70,100,100);
}
}}
运行后并不能看到Graphics的圆圈。
谢谢!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*; public class SimpleGui3C implements ActionListener {
JFrame frame;
public static void main (String[] args) {
SimpleGui3C gui = new SimpleGui3C();
gui.go();
}
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Change colors");
button.addActionListener(this);
MyDrawPanel One = new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.CENTER, One);
frame.setSize(300,300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
frame.repaint();
} class MyDrawPanel extends JPanel {
public void paintComponet(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
GradientPaint gradient = new GradientPaint(70,70,Color.blue,150,150,Color.orange);
g2d.setPaint(gradient);
g2d.fillOval(70,70,100,100);
}
}}
运行后并不能看到Graphics的圆圈。
谢谢!
解决方案 »
- 再次来这里求教,关于对话框输入数据,主窗口表格实时更新问题
- [Help] new File("ABC.TXT"); 的文件是在哪里?
- 简单问题:截取字符串函数
- javamail 发件人怎么指定?
- java编写的范例(初学者)!!十分感谢 !在线等
- 多维向量vector的长度如何获取
- 学习线程的wait ,notify,synchronized问题,请帮忙分析一小段程序,小弟不胜感激
- 请前辈谈谈static的机制!
- jBUILDER5下编的程序怎么在DOS下运行不了?
- 我的applet为什么只能在netscape下显示出来,IE6就显示不出来??
- 如何得到当前时间一个月以前的日期?
- 模糊匹配算法,还请高手指点。。。。
paintComponent拼写错误