每当我打开我的框架时,windowOpened应该打印“打开”,但它不打印。所有其他抽象方法都正常工作。我正在使用Java 7.对此行为的任何想法。
public class windowlistenerdemo extends Frame implements WindowListener
{
public windowlistenerdemo()
{
setSize(400,400);
setVisible(true);
this.addWindowListener(this);
}
@Override
public void windowOpened(WindowEvent e) {
System.out.println("open");
}
@Override
public void windowClosing(WindowEvent e) {
System.out.println("closing");
this.dispose();
}
@Override
public void windowClosed(WindowEvent e) {
System.out.println("closed");
}
public static void main(String[] args) {
windowlistenerdemo ob = new windowlistenerdemo();
}
}
答案 0 :(得分:4)
listener
您要在添加windowOpened
之前将窗口设置为可见。 public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Dictionary<string, UserControl1> myControls = new Dictionary<string, UserControl1>();
private void Form1_Load(object sender, EventArgs e)
{
// you could create the controls manually (i.e. not in designer)
// add them to a dictionary
// and also add them to the form, or whatever container you want
for (int i = 0; i < 40; i++)
{
var newControl = new UserControl1
{
Top = (i%10)*30,
Left = (i/10)*200,
};
myControls.Add("iButton" + ("ABCD"[(i / 10)]) + (i % 10), newControl);
this.Controls.Add(newControl);
}
// now you can reference any of these controls like this:
var letter = "B";
var num = "8";
var buttonItem = myControls["iButton" + letter + num].iButtonItem;
}
}
事件已经解雇。尝试交换这些行。