public class NumberGUI extends JFrame { /** * The constructor initializes all the GUI components. */ public NumberGUI() { this.setTitle("What does this do?"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new AppPanel(); this.getContentPane().add(panel); this.pack(); } /** * Dislays the frame. */ public static void main(String args[]) { NumberGUI x = new NumberGUI(); x.show(); } /** * <p>Title: AppPanel</p> * <p>Description: Builds and manages the GUI * * * @version 1.3 */ class AppPanel extends JPanel { //private Vector numbers; private MyListModel model; private JList numbersList; private JButton removeBtn, addBtn; private JTextField newNumberFld; /** * The constructor initializes all the GUI components. */ public AppPanel() { //numbers = new Vector(); model = new MyListModel(); //numbersList = new JList( numbers ); numbersList = new JList(model); numbersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); removeBtn = new JButton("Remove"); addBtn = new JButton("Add"); newNumberFld = new JTextField(6); ActionListener btnListener = new ButtonListener(); removeBtn.addActionListener(btnListener); addBtn.addActionListener(btnListener); JScrollPane listPane = new JScrollPane(); listPane.getViewport().add(numbersList); JPanel listPnl = new JPanel(); listPnl.setLayout(new BoxLayout(listPnl, BoxLayout.X_AXIS)); listPnl.add(Box.createRigidArea(new Dimension(10, 0))); listPnl.add(listPane); listPnl.add(Box.createRigidArea(new Dimension(10, 0))); JLabel addLbl = new JLabel("New Value: "); JPanel addPnl = new JPanel(); addPnl.add(Box.createRigidArea(new Dimension(10, 0))); addPnl.add(addLbl); addPnl.add(Box.createRigidArea(new Dimension(5, 0))); addPnl.add(newNumberFld); addPnl.add(Box.createRigidArea(new Dimension(10, 0))); JPanel btnPnl = new JPanel(); btnPnl.setLayout(new BoxLayout(btnPnl, BoxLayout.X_AXIS)); btnPnl.add(Box.createRigidArea(new Dimension(10, 0))); btnPnl.add(addBtn); btnPnl.add(Box.createRigidArea(new Dimension(10, 0))); btnPnl.add(removeBtn); btnPnl.add(Box.createRigidArea(new Dimension(10, 0))); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(Box.createRigidArea(new Dimension(0, 10))); add(listPnl); add(Box.createRigidArea(new Dimension(0, 5))); add(addPnl); add(Box.createRigidArea(new Dimension(0, 10))); add(Box.createVerticalGlue()); add(btnPnl); add(Box.createRigidArea(new Dimension(0, 10))); this.setPreferredSize(new Dimension(200, 200)); } private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { if (e.getSource() == addBtn) { String txt = newNumberFld.getText(); try { int num = Integer.parseInt(txt); /* numbers.add(new Integer( num )); Collections.sort(numbers); numbersList.setListData( numbers ); */ model.add(new Integer(num)); } catch (NumberFormatException ex) {} newNumberFld.setText(""); } else if (e.getSource() == removeBtn) { int i = numbersList.getSelectedIndex(); if (i >= 0) { /* numbers.remove( i ); numbersList.setListData( numbers ); */ model.remove(i); } } } } /** * <p>Title: MyListModel</p> */ public class MyListModel extends AbstractListModel { private ArrayList list = new ArrayList(); public void add(Object obj) { int pos = Collections.binarySearch(list, obj); //negative means not found. binarysearch returns -insertionpoint-1 if (pos < 0) { pos = - (pos + 1); } list.add(pos, obj); // notify listeners this.fireIntervalAdded(this, pos, pos); } public Object remove(int pos) { Object ret = list.remove(pos); // notify listeners this.fireIntervalRemoved(this, pos, pos); return ret; } public Object getElementAt(int i) { return list.get(i); } public int getSize() { return list.size(); } } }}EDIT:One of the staff members will be taking the quiz over for about a week.
GP-Rewarding Quiz
#1576
Posted 17 May 2009 - 08:27 PM
Present from:
(King Dedede)
A flash game - canabalt (thanks to TGIF gamespy)
Game Boy Advance Information Thread, Read this for Info, Common Topics, etc
VBALink, list of working and not working games
Pinned: NDS Emulators User's Guides
#1577
Posted 20 May 2009 - 10:36 PM
PSN: Verbalinter39
~I$h
#1578
Posted 20 May 2009 - 11:29 PM
Because We're Paying off Other Countries Debts Sending billions of dollars to other contriesand Giving money to companies Who were careless with cash Lets see Em Bail out the Video game companies atleast They'll be able to show for the money with Better gamesHaha. I guess no one got that one.+50Why is the U.S's deficit so huge?
#1579
Posted 20 May 2009 - 11:39 PM
PSN: Verbalinter39
~I$h
#1580
Guest_Josh Loves Anarchy
Posted 21 May 2009 - 12:29 AM
#1581
Guest_Lt Ambrose
Posted 21 May 2009 - 03:19 AM
#1582
Posted 21 May 2009 - 03:27 AM
PSN: Verbalinter39
~I$h
#1583
Guest_Shikra
Posted 21 May 2009 - 05:45 AM
Kutner commited suicide. They had to off his character because Kal Penn (the actor) is now the Associate Director of the White House Office of Public Liaison. (I don't even know what that isheh. correct to both. +50+100How was Cutner cut off the tv series House? Also what did he pursue to do in real life after his character was killed off?
#1584
Guest_Cypher03
Posted 21 May 2009 - 08:26 AM
Cutner committed suicide. in real life he became associate director of the white house office of public liason.10 GPs deducted, please read the rules! - Greenzheh. correct to both. +50+100How was Cutner cut off the tv series House? Also what did he pursue to do in real life after his character was killed off?
#1585
Guest_akcsfreak
Posted 22 May 2009 - 06:38 PM
I hope I don't get docked for this, as I'm just trying to be helpful, but basically what this means is that he's going help be a Publicist for the United States Government. I'm not 100% positive on this but in other words, he's specifically dealing with Government to general population relations and his job is to help make the United States Government look good and to point out all the things that they're doing to help. Which I suppose is particularly needed at this point in time as there's a lot of mixed feelings about the government.Kutner commited suicide. They had to off his character because Kal Penn (the actor) is now the Associate Director of the White House Office of Public Liaison. (I don't even know what that is
)
#1586
Posted 27 May 2009 - 06:55 AM
PSN: Verbalinter39
~I$h
#1587
Guest_mario1212
Posted 27 May 2009 - 12:55 PM
Edited by mario1212, 27 May 2009 - 12:56 PM.
#1588
Guest_General_Chang
Posted 28 May 2009 - 01:20 AM
#1589
Posted 28 May 2009 - 04:26 AM
PSN: Verbalinter39
~I$h
#1590
Guest_black lce
Posted 28 May 2009 - 05:10 AM
#1591
Guest_jjandab
Posted 31 May 2009 - 09:26 PM
Gracie Margaret KleinschmidtLuanne from King of the Hill has a daughter named Grace.
#1596
Guest_Lt Ambrose
Posted 08 June 2009 - 12:46 AM
#1597
Posted 11 June 2009 - 03:43 AM
PSN: Verbalinter39
~I$h
#1598
Guest_Elven Sniper
Posted 11 June 2009 - 03:50 AM
Futurama, because it worked when they ressurected family guy and network = comedy central+50 black ice & lt ambroseWhich canceled fox animated show is being brought back to the dead? For what reason and on what network?
#1599
Posted 11 June 2009 - 03:53 AM
PSN: Verbalinter39
~I$h
#1600
Guest_Elven Sniper
Posted 11 June 2009 - 03:57 AM


This topic is locked







