Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

number output swing java

**UPDATE: I GOT IT*******************

private int price;
private int setPrice;

*othercodes here*

private void setPrice(int price) {
    setPrice = setPrice + price;
    textField.setText(Integer.toString(setPrice));
}

btnNails.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setPrice(5);
        }
*************************************

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTable;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Frame52 extends JFrame {

    private JPanel contentPane;
    private JTextField textField;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Frame52 frame = new Frame52();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public Frame52() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);            
        JButton btnNails = new JButton("Nails");
        btnNails.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int getPrice = 0;
                getPrice = getPrice + 5;
            }
        });
        btnNails.setBounds(43, 70, 114, 23);
        contentPane.add(btnNails);          
        JButton btnWood = new JButton("Wood");
        btnWood.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int getPrice = 0;
                getPrice = getPrice + 20;
            }
        });
        btnWood.setBounds(43, 114, 114, 23);
        contentPane.add(btnWood);

        JButton btnNewButton = new JButton("Galvanized Iron");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int getPrice = 0;
                getPrice = getPrice + 30;
            }
        });
        btnNewButton.setBounds(43, 159, 114, 23);
        contentPane.add(btnNewButton);          
        JButton btnNewButton_1 = new JButton("Steel");
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                int getPrice = 0;
                getPrice = getPrice + 40;
            }
        });
        btnNewButton_1.setBounds(43, 203, 114, 23);
        contentPane.add(btnNewButton_1);            
        JLabel lblTotalIs = new JLabel("Total is:");
        lblTotalIs.setBounds(203, 163, 46, 14);
        contentPane.add(lblTotalIs);            
        textField = new JTextField();
        textField.setText(Integer.toString(getPrice));
        textField.setBounds(259, 160, 86, 20);
        contentPane.add(textField);
        textField.setColumns(10);           
        JButton btnConfirm = new JButton("Confirm");
        btnConfirm.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
            }
        });
        btnConfirm.setBounds(257, 203, 91, 23);
        contentPane.add(btnConfirm);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: asserttrue in selenium java 
Java :: sealed interface java codegrepper 
Java :: spring down load 
Java :: Java Default Access Modifier creates error in package two by importing package one 
Java ::         System.out.println("Welcone to GeeksforGeeks"); 
Java :: android getdrawable before api 21 
Java :: Calling the Pre-Defined Method in Java 
Java :: cancel block event spigot 
Java :: Java Create an OutputStreamWriter 
Java :: firebase timestamp to textview 
Java :: number pattern in java 
Java :: search in jdbc 
Java :: <selector xmlns:android="http://schemas.android.com/apk/res/android<item android;drawable="@drawable/bluebtn" android: state_enabled="false"/ 
Java :: string join in java 
Java :: mock a service when the method returning void 
Java :: 2 multiples 
Java :: java jdk invalidate intellij 
Java :: java.lang.StackOverflowError 
Java :: sudo visudo quit without saving 
Java :: jdk full form 
Java :: hint property of plain text in android studio 
Java :: Algorithms - Max value 
Java :: spigot check if inventory is empty 
Java :: java default keyword 
Java :: unmappable character java 
Java :: Java Private Access Modifier Error when we call it 
Java :: Java Copying Arrays Using arraycopy() method 
Java :: uncaught error java.net.sockettimeoutexception failed to connect 
Java :: Buscando Objeto do Array 
Java :: Java/Perl - "sprintf function in java" or "string format" 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =