ทดสอบการใช้ method ของ JFrame ซึ่งมีคุณสมบัติการ Enable และ Disable การใช้งาน windows ได้
[src]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WindowTest
extends JFrame
{
JFrame second = null;
public WindowTest (String title)
{
super (title);
}
public static void main (String[] args)
{
WindowTest wTest = new WindowTest ("Testing!");
wTest.Main (args);
return;
}
public void Main (String[] args)
{
second = new JFrame ("Second");
Button toggle = new Button ("Toggle enabled");
Container c= getContentPane();
c.add (toggle, "Center");
toggle.addActionListener (new ActionListener ()
{
public void actionPerformed (ActionEvent ae)
{
toggleValue();
}
});
addWindowListener (new WindowAdapter ()
{
public void windowClosing (WindowEvent we)
{
setSecondEnabled();
dispose();
return;
}
});
setSize (200, 300);
setVisible (true);
second.setSize (100, 150);
second.setVisible(true);
return;
}
public void toggleValue()
{
second.setEnabled(!second.isEnabled());
return;
}
public void setSecondEnabled ()
{
second.setEnabled (true);
return;
}
}
[/src]


Reply With Quote
