user interface - Basic Multiply and Divide Java GUI -
I am trying to find the number in which the user divides the input by 2 times the number of frames or 3 Depending on which button they decide to click I have a hard time trying to do this, I know that it is necessary to be in the methodology system.
import javax.swing. *; Import java.awt. *; Import java.awt.event. *; Public Square Quiz4 Extends JFrame ActionListener {// Global Variable Declaration // Our List Input Fields Private Jellabal Values Labels = New JLABEL ("Enter Value Between 1 and 20"); Private JTextField valueField = new JTextField (25); // Create Action Button Personal Zabetan Multibutan = New Pocket ("x2"); Personal Zebton Divide Button = New Pocket ("/ 3"); Private JScrollPane displayScrollPane; Private JTextArea display = new JTextArea (10,5); // input number private BufferedReader infirst; // Output Number Private Number Exited; Public Quiz 4 () {// Super ("List Transfer Tool"); GetContentPane () setLayout (new border layout ()); // Our Input Panel JPNL InputPanel = Create New ZipLine (New GridLayout (1,1)); InputPanel.add (valueLabel); InputPanel.add (valueField); . Adding GetContentPane () (inputPanel, "Center"); // Creating our diffPanel JPanel diffPanel and Population / New JPN (New Grid Layout (1,2,1,1)); DiffPanel.add (multiButton); DiffPanel.add (divideButton); GetContentPane () Add (diffPanel, "south"); //diffButton.addActionListener(this); } // Quiz 4 () Public Zero ActionPerfed (ActionAge AE) {} / ActionPerfed () Public Static Wide Men (String AGR []) {Quiz 4F = New Quiz 4 (); F.setSize (1200, 200); f.setVisible (true); F.addWindowListener (New WindowAdapter () {// Application Public Zero Window Closure (WindowEndE) {System.exit (0);}}); } // main ()}
Here's something simple, but this Essentially you want to get out of your program. To handle everything I wanted, I had to add the ActionAlliston to each button that was written in the text box. I just approve the ActionListener in the button, and then the methodology in action, I define what I should do. Import java.awt.FlowLayout; Import java.awt.event.ActionEvent; Import java.awt.event.ActionListener; Import javax.swing.JButton; Import javax.swing.JFrame; Import javax.swing.JLabel; Import javax.swing.JPanel; Import javax.swing.JTextField; Import javax.swing.SwingUtilities; Public Square Quizx JFrame {Personal JP panel; Private JTextField textfield; Private JLab ansLabel; Public quiz () {panel = new zpinal (new flow layout ()); . Adding this.getContentPane () (panel); AddLabel (); AddTextField (); AddButtons (); AddAnswerLabel (); this.setDefaultCloseOperation (JFrame.DISPOSE_ON_CLOSE); This.setTitle ("Quiz 4"); This.setSize (220, 150); This.setLocationRelativeTo (zero); This.setResizable (wrong); This.setVisible (true); } Private Zero addTextField () {textfield = new JTextField (); Textfield.setColumns (9); Panel.add (field); } Private Zero addButtons () {JButton multButton = New JButton ("x2"); Jebton Debutton = New Pocket ("/ 3"); Panel.add (multButton); Panel.add (divButton); AddMultListener (multButton); AddDivListener (divButton); } Private Zero addLabel () {JLabel value label = New JLabel ("Enter a value between 1 and 20:"); Panel.add (valueLabel); } Private Zero addAnswerLabel () {ansLabel = new JLabel (); panel.add (ansLabel); } Private Zero AddMultListener (JButton Button) {button.addActionListener (New ActionListener) {@Override Public Zero Action Performed (ActionEvent arg0) {ansLabel.setText (String.valueOf (Integer.parseInt (textfield.getText). Trim ()) * 2));}}); } Private Zero addDivListener (JButton Button) {button.addActionListener (New ActionListener) {@Override Public Zero Action Performed (ActionEvent arg0) {ansLabel.setText (String.valueOf (Double.parseDouble (textfield.getText). Trim ()) / 3));}}); } Public static zero main (string [] args) {SwingUtilities.invokeLater (New Runnabel) {@Override Public Zero () {New Quizx ();}}); }} Hope that helps.
Comments
Post a Comment