Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Java
  4. JButton Help

JButton Help

Scheduled Pinned Locked Moved Java
javawpftoolsarchitecturehelp
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    James WG Murphy
    wrote on last edited by
    #1

    I am currently writing a program which will perform binary to decimal, decimal to binary, hexadecimal to decimal, decimal to hexadecimal conversions, 1's compliment, 2's compliment, and show the list of boolean algebra rules. I have created the JFrame and the JButtons to create the GUI however, I cannot figure out how to make each of these Jbuttons open up a new frame or panel. Please help me. I will attach the file and the code is below:

    *
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /*
    * ConversionGUI.java
    *
    * Created on Mar 16, 2010, 4:50:30 PM
    */

    package c;

    import javax.swing.JFrame;

    /**
    *
    * @author James
    */
    public class ConversionGUI extends javax.swing.JFrame {

    /** Creates new form ConversionGUI */

    public ConversionGUI() {
    initComponents();
    }

    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    jButton1 = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    jButton2 = new javax.swing.JButton();
    jLabel2 = new javax.swing.JLabel();
    jButton3 = new javax.swing.JButton();
    jLabel3 = new javax.swing.JLabel();
    jButton4 = new javax.swing.JButton();
    jLabel4 = new javax.swing.JLabel();
    jButton5 = new javax.swing.JButton();
    jLabel5 = new javax.swing.JLabel();
    jButton6 = new javax.swing.JButton();
    jLabel6 = new javax.swing.JLabel();
    jButton7 = new javax.swing.JButton();
    jLabel7 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("Computer Architecture Converter");

    jButton1.setText("Binary to Decimal");

    jLabel1.setText("B2D");

    jButton2.setText("Decimal to Binary");

    jLabel2.setText("D2B");

    jButton3.setText("Hexadecimal to Decimal");

    jLabel3.setText("H2D");

    jButton4.setText("Decimal to Hexadecimal");

    jLabel4.setText("D2H");

    jButton5.setText("Library of Boolean Algebra Rules");

    jLabel5.setText("LBAR");

    jButton6.setText("1's Complement");

    jLabel6.setText("2C");

    jButton7.setText("2's Compliment");

    jLabel7.setText("1C");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.c

    L D 2 Replies Last reply
    0
    • J James WG Murphy

      I am currently writing a program which will perform binary to decimal, decimal to binary, hexadecimal to decimal, decimal to hexadecimal conversions, 1's compliment, 2's compliment, and show the list of boolean algebra rules. I have created the JFrame and the JButtons to create the GUI however, I cannot figure out how to make each of these Jbuttons open up a new frame or panel. Please help me. I will attach the file and the code is below:

      *
      * To change this template, choose Tools | Templates
      * and open the template in the editor.
      */

      /*
      * ConversionGUI.java
      *
      * Created on Mar 16, 2010, 4:50:30 PM
      */

      package c;

      import javax.swing.JFrame;

      /**
      *
      * @author James
      */
      public class ConversionGUI extends javax.swing.JFrame {

      /** Creates new form ConversionGUI */

      public ConversionGUI() {
      initComponents();
      }

      /** This method is called from within the constructor to
      * initialize the form.
      * WARNING: Do NOT modify this code. The content of this method is
      * always regenerated by the Form Editor.
      */
      @SuppressWarnings("unchecked")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">
      private void initComponents() {

      jButton1 = new javax.swing.JButton();
      jLabel1 = new javax.swing.JLabel();
      jButton2 = new javax.swing.JButton();
      jLabel2 = new javax.swing.JLabel();
      jButton3 = new javax.swing.JButton();
      jLabel3 = new javax.swing.JLabel();
      jButton4 = new javax.swing.JButton();
      jLabel4 = new javax.swing.JLabel();
      jButton5 = new javax.swing.JButton();
      jLabel5 = new javax.swing.JLabel();
      jButton6 = new javax.swing.JButton();
      jLabel6 = new javax.swing.JLabel();
      jButton7 = new javax.swing.JButton();
      jLabel7 = new javax.swing.JLabel();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      setTitle("Computer Architecture Converter");

      jButton1.setText("Binary to Decimal");

      jLabel1.setText("B2D");

      jButton2.setText("Decimal to Binary");

      jLabel2.setText("D2B");

      jButton3.setText("Hexadecimal to Decimal");

      jLabel3.setText("H2D");

      jButton4.setText("Decimal to Hexadecimal");

      jLabel4.setText("D2H");

      jButton5.setText("Library of Boolean Algebra Rules");

      jLabel5.setText("LBAR");

      jButton6.setText("1's Complement");

      jLabel6.setText("2C");

      jButton7.setText("2's Compliment");

      jLabel7.setText("1C");

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.c

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to add action listeners to your buttons which get fired when the button is clicked. See here[^] for a sample.

      txtspeak is the realm of 9 year old children, not developers. Christian Graus

      J 1 Reply Last reply
      0
      • J James WG Murphy

        I am currently writing a program which will perform binary to decimal, decimal to binary, hexadecimal to decimal, decimal to hexadecimal conversions, 1's compliment, 2's compliment, and show the list of boolean algebra rules. I have created the JFrame and the JButtons to create the GUI however, I cannot figure out how to make each of these Jbuttons open up a new frame or panel. Please help me. I will attach the file and the code is below:

        *
        * To change this template, choose Tools | Templates
        * and open the template in the editor.
        */

        /*
        * ConversionGUI.java
        *
        * Created on Mar 16, 2010, 4:50:30 PM
        */

        package c;

        import javax.swing.JFrame;

        /**
        *
        * @author James
        */
        public class ConversionGUI extends javax.swing.JFrame {

        /** Creates new form ConversionGUI */

        public ConversionGUI() {
        initComponents();
        }

        /** This method is called from within the constructor to
        * initialize the form.
        * WARNING: Do NOT modify this code. The content of this method is
        * always regenerated by the Form Editor.
        */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jButton7 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Computer Architecture Converter");

        jButton1.setText("Binary to Decimal");

        jLabel1.setText("B2D");

        jButton2.setText("Decimal to Binary");

        jLabel2.setText("D2B");

        jButton3.setText("Hexadecimal to Decimal");

        jLabel3.setText("H2D");

        jButton4.setText("Decimal to Hexadecimal");

        jLabel4.setText("D2H");

        jButton5.setText("Library of Boolean Algebra Rules");

        jLabel5.setText("LBAR");

        jButton6.setText("1's Complement");

        jLabel6.setText("2C");

        jButton7.setText("2's Compliment");

        jLabel7.setText("1C");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
        layout.c

        D Offline
        D Offline
        David Skelly
        wrote on last edited by
        #3

        The first thing I would do if I was you is to buy a good book on Swing programming. Sun do a very good one. If you can't afford that, there are some good tutorials on the Sun site that will lead you through the basics.

        1 Reply Last reply
        0
        • L Lost User

          You need to add action listeners to your buttons which get fired when the button is clicked. See here[^] for a sample.

          txtspeak is the realm of 9 year old children, not developers. Christian Graus

          J Offline
          J Offline
          James WG Murphy
          wrote on last edited by
          #4

          I have right clicked on the buttons and added action listeners but I am not sure what coding to enter to establish new jpanels or new jframes. Sun's tutorials do not explain this matter either

          L D 2 Replies Last reply
          0
          • J James WG Murphy

            I have right clicked on the buttons and added action listeners but I am not sure what coding to enter to establish new jpanels or new jframes. Sun's tutorials do not explain this matter either

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            I think you may need the Internal Frame[^] class. I would also suggest you try working through some of the swing tutorials, just to get familiar and comfortable with the components and how they fit together. If you are just using drag and drop through NetBeans it is not always clear how the various pieces interact.

            txtspeak is the realm of 9 year old children, not developers. Christian Graus

            1 Reply Last reply
            0
            • J James WG Murphy

              I have right clicked on the buttons and added action listeners but I am not sure what coding to enter to establish new jpanels or new jframes. Sun's tutorials do not explain this matter either

              D Offline
              D Offline
              David Skelly
              wrote on last edited by
              #6

              To show a frame you call setVisible(true). The Sun tutorial is here: http://java.sun.com/docs/books/tutorial/uiswing/TOC.html[^] The tutorial is pretty comprehensive. Swing is a big toolkit, and it's not really something you can learn in an afternoon, so be prepared to invest some time learning it if you want to get the best from it.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups