浏览 3682 次
锁定老帖子 主题:在JPanel画字符串的问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2006-11-21
public class MainFrame extends JFrame { private Percent percent; public MainFrame() { super("Color Chooser"); container = getContentPane(); container.setLayout(new FlowLayout()); percent = new Percent(); percent.setBackground(Color.BLUE); container.add(percent); setSize(400,130); setVisible(true); } public static void main(String args[]) { ColorChooser myColorChooser = new ColorChooser(); myColorChooser.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } private class Percent extends JPanel { private float redPercent = 100; private float greenPercent; private float bluePercent; public void paintComponenet(Graphics g) { super.paintComponent(g); g.setColor(Color.BLACK); g.setFont(new Font("Serif",Font.BOLD,12)); g.drawString("RED:" + redPercent + "%", 10, 20); g.drawString("GREEN:" + greenPercent + "%", 10, 100); g.drawString("BLUE:" + bluePercent + "%", 10, 180); } public void setPercent(int r, int g, int b) { int total = r + g + b; redPercent = 100 * (float) r / (float) total; greenPercent = 100 * (float) r / (float) total; bluePercent = 100 - redPercent - greenPercent; repaint(); } public Dimension getPreferredSize() { return new Dimension(200, 200); } // used by layout manager to determine minimum size public Dimension getMinimumSize() { return getPreferredSize(); } } 我不会贴图,所以无法把运行结果贴出来了。口头描述一下结果:加入的Percent这个JPanel上面没有画上字符串,不知道是为什么? 能不能帮我看看代码是不是有问题?Thanks!!! 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2006-11-21
paintComponenet
paintComponent the same ? |
|
返回顶楼 | |