//creates a window with three object in it: label, menu, dynamic label. //todo: //5/17 fixed,ndd bgr gridspace>>5/16 works, but needs textfield listener length adjustment // import javax.swing.*; import java.awt.*; import java.awt.event.*; public class TBox implements WindowListener, ItemListener, ActionListener { JFrame aFrame=null; JButton btn1=null; JLabel txt1=null; Container contents=null; BorderLayout blt=new BorderLayout(); BorderLayout blt2=new BorderLayout(); int clickNum=0; public Container mComps() { contents=new Container(); contents.setLayout(blt2); this.btn1=new JButton("Click"); this.btn1.setMnemonic(KeyEvent.VK_B); this.btn1.setActionCommand("btn1"); this.btn1.addActionListener(this); this.txt1=new JLabel("# of Clicks:"+clickNum); contents.add(this.btn1, BorderLayout.EAST); contents.add(this.txt1, BorderLayout.WEST); return contents; } //constructor public TBox(String nameS, int sizx, int sizy){ this.aFrame=new JFrame(nameS); this.aFrame.getContentPane().setLayout(blt); this.aFrame.getContentPane().add(this.mComps()); this.aFrame.addWindowListener(this); this.aFrame.pack(); this.aFrame.setSize(400,200); this.aFrame.setVisible(true); } //WindowListener:: public void windowClosing(WindowEvent e) { Window theWindow=e.getWindow(); theWindow.dispose(); } public void windowClosed(WindowEvent e) { System.exit(0); } public void windowActivated(WindowEvent e) {} public void windowDeactivated(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowOpened(WindowEvent e) { } //ItemListener:: public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { } } //ActionListener:: public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("btn1") ){ clickNum++; txt1.setText("# of clicks: "+clickNum); } } }