当前位置: 技术问答>java相关
sos 我遇到了一个问题望高手指教
来源: 互联网 发布时间:2015-01-20
本文导语: 原程序如下: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class ButtonIconTest { public static void main(String ags[]) { JButton b; Icon icon=new PieIcon(Color.red); b=new JButton("a java button",icon);...
原程序如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonIconTest
{
public static void main(String ags[])
{
JButton b;
Icon icon=new PieIcon(Color.red);
b=new JButton("a java button",icon);
Frame frame= new Frame("123");
frame.setBackground(Color.blue);
frame.setSize(400,400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
//public void class WindowAdapter()
frame.show();
frame.add(b,BorderLayout.NORTH);
}
static class PieIcon implements Icon
{
Color color;
public PieIcon(Color c)
{
color=c;
}
public int getIconWidth()
{
return 20;
}
public int getIconHeight()
{
return 20;
}
public void paintIcon(Component c,Graphics g, int x,int y)
{
g.setColor(color);
g.fillArc(x,y,getIconWidth(),getIconHeight(),45,270);
}
}
}
但是在出来的窗口里找不到按钮,这时怎么回事呀?望各位高手指教一二!!
在这里先谢过了。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonIconTest
{
public static void main(String ags[])
{
JButton b;
Icon icon=new PieIcon(Color.red);
b=new JButton("a java button",icon);
Frame frame= new Frame("123");
frame.setBackground(Color.blue);
frame.setSize(400,400);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
//public void class WindowAdapter()
frame.show();
frame.add(b,BorderLayout.NORTH);
}
static class PieIcon implements Icon
{
Color color;
public PieIcon(Color c)
{
color=c;
}
public int getIconWidth()
{
return 20;
}
public int getIconHeight()
{
return 20;
}
public void paintIcon(Component c,Graphics g, int x,int y)
{
g.setColor(color);
g.fillArc(x,y,getIconWidth(),getIconHeight(),45,270);
}
}
}
但是在出来的窗口里找不到按钮,这时怎么回事呀?望各位高手指教一二!!
在这里先谢过了。
|
frame.show();
frame.add(b,BorderLayout.NORTH);
frame.validate();// add a line here
frame.add(b,BorderLayout.NORTH);
frame.validate();// add a line here