Big Snooze's Profile
Reputation: 2
Apprentice
- Group:
- Members
- Active Posts:
- 26 (0.11 per day)
- Joined:
- 26-September 12
- Profile Views:
- 441
- Last Active:
Dec 17 2012 01:50 PM- Currently:
- Offline
Previous Fields
- Country:
- US
- OS Preference:
- Who Cares
- Favorite Browser:
- Chrome
- Favorite Processor:
- AMD
- Favorite Gaming Platform:
- Who Cares
- Your Car:
- Chevrolet
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Problem with JMenus
Posted 28 Nov 2012
Ah, good point. I guess for some reason I was under the assumption that it was required to make a new one -
In Topic: Problem with JMenus
Posted 28 Nov 2012
The frame was in another class, however theevent.getSource().getTopLevelAncestor()
Worked perfectly, I see what was going wrong now. Thanks! -
In Topic: JTextField string to int
Posted 6 Nov 2012
Disregard that last post, I believe I've finally figured it out and am implementing the conversions based on the boxes checked!
-
In Topic: JTextField string to int
Posted 5 Nov 2012
I mean it is, I understand what it does I was just trying to relate that to the code I have already written. Took a year off so I am a tad rusty. I tried to implement your example into my own and created more errors and problems.
I'm at a theatrical flashing red light, I'm not sure where to turn now. Here are my two code files, would you mind giving me a few suggestions about doing something similar above that would work into what I have?
baseconversion.java: (This is the file that builds the GUI so to speak)
import java.awt.BorderLayout; import java.awt.Component; import java.awt.Image; import java.awt.Toolkit; import java.awt.event.*; import javax.swing.*; import javax.swing.border.TitledBorder; public class Baseconversion { public Baseconversion() { } public static void main(String[] args) { final JFrame myApp = new JFrame ("Masters Base Converter"); myApp.setSize(400, 350); myApp.setResizable(false); myApp.setLocationRelativeTo(null); myApp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Image icon = Toolkit.getDefaultToolkit().getImage("Images/icon32x32.gif"); myApp.setIconImage(icon); myApp.setVisible(true); try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception e) { System.out.println("Unable to load Windows look and feel"); } int[] inputBase = {2, 8, 10, 16}; TitledBorder title1; title1 = BorderFactory.createTitledBorder("Your Number"); title1.setTitleJustification(TitledBorder.CENTER); TitledBorder title2; title2 = BorderFactory.createTitledBorder("The Base"); title2.setTitleJustification(TitledBorder.CENTER); TitledBorder title3; title3 = BorderFactory.createTitledBorder("Your Result"); title3.setTitleJustification(TitledBorder.CENTER); // JFrame Parts //////////////////////////////////////////////////// JPanel panelTop = new JPanel(); JPanel panelCenter1 = new JPanel(); JPanel panelCenter2 = new JPanel(); JPanel panelCenter3 = new JPanel(); JPanel panelBottom = new JPanel(); JPanel thePanel = new JPanel(new BorderLayout()); JLabel instructions = new JLabel("Please enter your number:"); final JPanel startBasePanel = new JPanel(new BorderLayout()); final JPanel resultBasePanel = new JPanel(new BorderLayout()); Box theBox = Box.createVerticalBox(); final JTextField field = new JTextField("here", 20); field.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Entered: " + field.getText()); //System.out.println("Int value:" + newNumber); }} ); final JTextField resultField = new JTextField("RESULT GOES HERE", 20); resultField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { }} ); JButton convert = new JButton("Convert!"); convert.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Component[] components = startBasePanel.getComponents(); } }); ///////////////////////////////////////////////////////////////////// // Calls NumberCheckBox.java for base check boxes NumberCheckBox.NumberCheckBoxes(myApp, startBasePanel, resultBasePanel); instructions.setLayout(new BorderLayout()); panelTop.add(instructions, BorderLayout.NORTH); panelTop.add(field, BorderLayout.CENTER); panelCenter1.setBorder(title2); panelCenter2.add(startBasePanel, BorderLayout.WEST); panelCenter2.add(resultBasePanel, BorderLayout.EAST); panelCenter3.add(convert); panelCenter1.add(panelCenter2); panelCenter1.add(panelCenter3); panelBottom.setBorder(title3); panelBottom.add(resultField); theBox.add(panelCenter1); theBox.add(panelCenter3); thePanel.add(panelTop, BorderLayout.NORTH); thePanel.add(theBox, BorderLayout.CENTER); thePanel.add(panelBottom, BorderLayout.SOUTH); myApp.add(thePanel); panelTop.setBorder(title1); } }
and
NumberCheckBox.java: (this file contains my base option boxes)
import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.ButtonGroup; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.TitledBorder; public class NumberCheckBox extends JPanel implements ItemListener { static JCheckBox binaryButton1; static JCheckBox octalButton1; static JCheckBox decimalButton1; static JCheckBox hexadecimalButton1; static JCheckBox binaryButton2; static JCheckBox octalButton2; static JCheckBox decimalButton2; static JCheckBox hexadecimalButton2; public static void NumberCheckBoxes(JFrame myApp, JPanel startBasePanel, JPanel resultBasePanel) { TitledBorder title1; title1 = BorderFactory.createTitledBorder("Starting Base"); title1.setTitleJustification(TitledBorder.CENTER); TitledBorder title2; title2 = BorderFactory.createTitledBorder("End Base"); title2.setTitleJustification(TitledBorder.CENTER); Box theBox1 = Box.createVerticalBox(); Box theBox2 = Box.createVerticalBox(); final ButtonGroup startBase = new ButtonGroup(); final ButtonGroup endBase = new ButtonGroup(); binaryButton1 = new JCheckBox("Binary"); binaryButton1.setSelected(false); octalButton1 = new JCheckBox("Octal"); octalButton1.setSelected(false); decimalButton1 = new JCheckBox("Decimal"); decimalButton1.setSelected(true); hexadecimalButton1 = new JCheckBox("Hexadecimal"); hexadecimalButton1.setSelected(false); startBase.add(binaryButton1); startBase.add(octalButton1); startBase.add(decimalButton1); startBase.add(hexadecimalButton1); theBox1.add(binaryButton1); theBox1.add(octalButton1); theBox1.add(decimalButton1); theBox1.add(hexadecimalButton1); binaryButton2 = new JCheckBox("Binary"); binaryButton2.setSelected(true); octalButton2 = new JCheckBox("Octal"); octalButton2.setSelected(false); decimalButton2 = new JCheckBox("Decimal"); decimalButton2.setSelected(false); hexadecimalButton2 = new JCheckBox("Hexadecimal"); hexadecimalButton2.setSelected(false); endBase.add(binaryButton2); endBase.add(octalButton2); endBase.add(decimalButton2); endBase.add(hexadecimalButton2); theBox2.add(binaryButton2); theBox2.add(octalButton2); theBox2.add(decimalButton2); theBox2.add(hexadecimalButton2); startBasePanel.setBorder(title1); startBasePanel.add(theBox1); resultBasePanel.setBorder(title2); resultBasePanel.add(theBox2); } public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub } }
I hope this isn't info-overload.. feel free to pick it apart too if your up to it. Should my text field and converting button be in the second file rather than the first? -
In Topic: JTextField string to int
Posted 5 Nov 2012
pbl, on 05 November 2012 - 02:27 PM, said:private int[] inputBase = {2, 8. 10, 15, 16, 32}; private JRadioButton[] radio; private JTextField tf; ... { radio = new JRadioButton[inputBase.length]; ButtonGroup bg = new ButtonGroup(); for(int i = 0; i < inputBase.length; ++i) { radio[i] = new JRadioButton("TextField base: " + inputBase[i]); add(radio[i]); bg.add(radio[i]); } } public void sctionPerformed(ActioneEvent e) { for(int i = 0; i < radio.length; ++i) { if(radio[i].isSelected()) { int number = Integer.parseInt(tf.getText(), inputBase[i]); System.out.println("Number is " + number + " in decimal"); return; } } }

I can't thank you enough, could you give me a quick walk through of that code
My Information
- Member Title:
- New D.I.C Head
- Age:
- 21 years old
- Birthday:
- February 8, 1992
- Gender:
-
- Location:
- College
- Interests:
-
Computer Programming, specifically C++ and in the process of Java.
Love graphic design. Anything to deal with Photoshop and Illustrator or any adobe product.
Big time sports fan and basketball player.
ΛXA - Years Programming:
- 3
- Programming Languages:
- C, C++, Java, Sql
Contact Information
- E-mail:
- Private
- Twitter:
- M_Masterz
|
|


Find Topics
Find Posts
View Reputation Given
|