如何添加JButton
到我的Canvas
?如何将JButton添加到Canvas()?或者如何将JButton添加到Panel()并将Panel()背景设置为透明?
public class mywindow extends Window
{
private static final Canvas canvas = new Canvas();
private JButton button;
public mywindow
{
super(new Frame());
button = new JButton("close");
setLayout (new BorderLayout());
//Step 1 - failed
add("North", canvas);
canvas.setSize(300,300);
canvas.setLocation(0,0);
// button = new JButton(my, "close"); will not work
// How can I add the button to the canvas?
//Step 2 - works, but it gets the background color, instead of real transparency.
//JPanel p = new JPanel(); p.setOpaque(false);
//p.setSize(300,300); p.setLocation(0,0);
//add("North", p);
//p.add("Left", button);
}
}
你为什么要把AWT和Swing混合?为什么不简单地坚持一个全Swing GUI?而且为什么你不必要地将类字段静态化? –