PDA

View Full Version : this.getFrame().setDefaultCloseOperation(WindowCon stants.DO_NOTHING_ON_CLOSE)



adamak88
پنج شنبه 08 مهر 1389, 18:49 عصر
this.getFrame().setDefaultCloseOperation(WindowCon stants.DO_NOTHING_ON_CLOSE);کار نمیکنه
پروژم swing application است
در سازنده بعد از initComponents() این کد را مینویسم

javaphantom
پنج شنبه 08 مهر 1389, 19:46 عصر
this.getFrame().setDefaultCloseOperation(WindowCon stants.DO_NOTHING_ON_CLOSE);کار نمیکنه
پروژم swing application است
در سازنده بعد از initComponents() این کد را مینویسم


حالا شما یکبارم قبلش بذار ببین چی می شه

adamak88
پنج شنبه 08 مهر 1389, 20:48 عصر
super(app);
System.out.println(this.getFrame().getDefaultClose Operation());
this.getFrame().setDefaultCloseOperation(WindowCon stants.DO_NOTHING_ON_CLOSE);
System.out.println(this.getFrame().getDefaultClose Operation());

initComponents();فرقی نکرد باز هم کار نمیکنه ، مقدارش از 1 به 0 تبدیل میشه ولی باز پنجره بسته میشه

Pouri_sb
جمعه 09 مهر 1389, 01:10 صبح
آخرین دستور سازنده باید باشه ها

adamak88
جمعه 09 مهر 1389, 19:30 عصر
هیچ فرقی نمیکنه
کار نمیکنه

public TestView(SingleFrameApplication app) {
super(app);
System.out.println(this.getFrame().getDefaultClose Operation());
this.getFrame().setDefaultCloseOperation(WindowCon stants.DO_NOTHING_ON_CLOSE);
System.out.println(this.getFrame().getDefaultClose Operation());
initComponents();

// status bar initialization - message timeout, idle icon and busy animation, etc
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);

// connecting action tasks to status bar via TaskMonitor
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
progressBar.setVisible(true);
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
}

mohsensaghafi
جمعه 09 مهر 1389, 21:22 عصر
سلام دوست عزیز.
در سازنده بعد از ()initComponents این دستور رو قرار بده.


this.setDefaultCloseOperation(WindowConstants.DO_N OTHING_ON_CLOSE);

adamak88
جمعه 09 مهر 1389, 23:23 عصر
کار نمیکنه
یه برنامه ساده swing application است که میخام قبل از بسته شدن یه اخطار بیاد و امکان کنسل شدن بستن پنجره باشد ولی نمیشه، این کد اثری نداره

public TestView(SingleFrameApplication app) {
super(app);

initComponents();
this.getFrame().setDefaultCloseOperation(WindowCon stants.DO_NOTHING_ON_CLOSE);
// status bar initialization - message timeout, idle icon and busy animation, etc
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);

// connecting action tasks to status bar via TaskMonitor
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
progressBar.setVisible(true);
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
}

mohsensaghafi
شنبه 10 مهر 1389, 17:06 عصر
سلام دوست عزیز.
این تغییرات رو اعمال کنید
این کد رو به برنامتون اضافه کنید. یعنی برای onClosing event این کد رو بنویسید.

private void formWindowClosing(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
if (confirmClose()) {
System.out.println("Window is closing");
System.exit(0);

}
}


private boolean confirmClose() {
int n = JOptionPane.showConfirmDialog(this,"Are you sure you want to Exit?","Confirm",JOptionPane.YES_NO_OPTION);
return n == JOptionPane.YES_OPTION;
}
و اون تابع رو زیرش اضافه کنید.
از طریق صفحه design فرم را روی Do_Nothing ست کنید.
اگر با چیزی غیر از NetBeans کد می نویسید بگید تا مراحل رو کامل بگم.
موفق باشید

adamak88
شنبه 10 مهر 1389, 21:06 عصر
ممنون از راهنماییت
ولی من پروژم swing application است
یک frame view خودش ایجاد میکنه که property هاش متفاوته، تو swing application نمیشه

a_r0711
دوشنبه 08 آذر 1389, 23:01 عصر
سلام مکه قراره این کد کاری کنه
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOS E);
به نظر من درسترش اینه ولی خوب کاری انجام نمیده

saeedIRHA
چهارشنبه 10 آذر 1389, 14:57 عصر
ممنون از راهنماییت
ولی من پروژم swing application است
یک frame view خودش ایجاد میکنه که property هاش متفاوته، تو swing application نمیشه


تابع windowClosing برای Frame ت رو Override کن، مثال:
http://leepoint.net/notes-java/GUI/containers/10windows/12frameclose.html