Tutorial Addendum on Beat - Beat JInternalFrame
| |
Internal Anatomy Listeners
The afterward program shows you how to make centralized anatomy listeners:
/**
* JInternalFrameListenerTest.java
* Absorb (c) 2002 by Dr. Yang
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public chic JInternalFrameListenerTest
accouterments InternalFrameListener, ActionListener {
JFrame myFrame = null;
int calculation = 0;
accessible changeless abandoned main(String[] a) {
(new JInternalFrameListenerTest()).test();
}
clandestine abandoned test() {
myFrame = new JFrame("Internal Anatomy Adviser Test");
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(300,300);
myFrame.setContentPane(new JDesktopPane());
JMenuBar myMenuBar = new JMenuBar();
JMenu myMenu = new JMenu("Frame");
JMenuItem myMenuItem = new JMenuItem("New");
myMenuItem.addActionListener(this);
myMenu.add(myMenuItem);
myMenuBar.add(myMenu);
myFrame.setJMenuBar(myMenuBar);
myFrame.setVisible(true);
}
accessible abandoned actionPerformed(ActionEvent e) {
count++;
JInternalFrame f = new JInternalFrame("Frame "+count);
f.setResizable(true);
f.setClosable(true);
f.setMaximizable(true);
f.setIconifiable(true);
f.setSize(200,200);
f.setLocation(count*10,count*10);
f.addInternalFrameListener(this);
f.setVisible(true);
myFrame.getContentPane().add(f);
}
accessible abandoned internalFrameActivated(InternalFrameEvent e) {
System.out.println("Internal anatomy activated");
}
accessible abandoned internalFrameClosed(InternalFrameEvent e) {
System.out.println("Internal anatomy closed");
}
accessible abandoned internalFrameClosing(InternalFrameEvent e) {
System.out.println("Internal anatomy closing");
}
accessible abandoned internalFrameDeactivated(InternalFrameEvent e) {
System.out.println("Internal anatomy deactivated");
}
accessible abandoned internalFrameDeiconified(InternalFrameEvent e) {
System.out.println("Internal anatomy deiconified");
}
accessible abandoned internalFrameIconified(InternalFrameEvent e) {
System.out.println("Internal anatomy iconified");
}
accessible abandoned internalFrameOpened(InternalFrameEvent e) {
System.out.println("Internal anatomy opened");
}
}
Run this program, you will see a bare anatomy with one card alleged "Frame". If you:
- Click "Frame" card and "New" card account to make first centralized frame.
- Click "Frame" card and "New" card account to make additional centralized frame.
- Click the abutting figure on the first centralized frame.
- Click the aerate figure on the additional centralized frame.
- Click the abbreviate figure on the additional centralized frame.
- Click the minimized angel of the additional centralized frame.
you will see the afterward letters generated from the centralized anatomy adviser methods.
Action performed - Clicked "New" card item
Internal anatomy opened
Action performed - Clicked "New" card item
Internal anatomy opened
Internal anatomy closing - Clicked the abutting icon
Internal anatomy closed
Internal anatomy activated - Clicked the aerate icon
Internal anatomy deactivated - Clicked the abbreviate icon
Internal anatomy iconified
Internal anatomy activated - Clicked the minimized image
Internal anatomy deiconified
|
frame, internal, public, myframe, system, println, internalframeevent, click, clicked, swing, second, import, jinternalframe, iconinternal, activated, count, jinternalframelistenertest, create, jframe, mymenubar, mymenu, mymenuitem, , internal frame, public void, println internal, system out, frame click, clicked the, click the, new menu, second internal, iconinternal frame, frame activated, println internal frame, internal frame click, second internal frame, new menu iteminternal, menu iteminternal frame, frame activated clicked, new menu item, import javax swing, internal frame listener, click frame menu, swing swing jinternalframe, |
Also see ...
This affiliate describes:JRadioButton chic and its accompanying classes.Different types contest accompanying radio buttons.How to acquisition the called radio button./
This program creates two radio buttons and puts them in a individual button group. Each button has 3 admirers to handle 3 altered types of events. A adverse is used in the adviser chic to advice to analyze the adjustment
This affiliate discusses: What is a layout? BorderLayout FlowLayout BoxLayout GridLayout GridBagLayout
Here is my sample program I wrote to do this with FlowLayout: /** * FlowLayoutTest.java * Absorb (c) 2002 by Dr. Yang */import java.awt.*;import javax.swing.*;public chic F
Run it. What do you anticipate about the result? Abundant better, right? But if you attending closely, amount apparatus are not accumbent to the correspondinglabel components. It is about absurd to adjus
GridBagLayoutjava.awt.GridBagLayout A added circuitous blueprint that:Divides the alembic into rows and columns. The amount of rows andthe amount of co