This is a java program, i will like the program the same way that is on the exam
ID: 3808859 • Letter: T
Question
This is a java program, i will like the program the same way that is on the example, like the screenshot that is posted please.. type it and paste it please
help me
Create a simple calculator application that adds two numbers. The purpose of this assignment is to explore UI elements and event listeners. Create a single class to hold your main instance, which will instantiate a UErame and attach an instance of your el class Create the culat class. This class should resize the main panel (itself and create two sub-panels, each sized so they will fit side-by-side. Into the left panel, add two text boxes (with labels) and a button. Into the right panel add three labels. as shown below. Dumb Calculator First Value: First Value: Second Value: Second Value: Total Calculate Add a listener to each of the textboxes so that when a person presses 'Enter', the label on the right panel updates. Add a listener to the 'Calculate' button so that when a person presses it, the total updates. For this assignment, you can safely assume that the calculate button is only pressed when there are values assigned When the button is clicked, it should look like this: Dumb Calculator First Value: 5 First Value: 5 Second Value: 3 Second Value 3 Total: 8 Calculate For 5% extra credit, attach the same event listener class to both textboxes (hint: pass a reference to the target label to the constructor.Explanation / Answer
code.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class code extends JFrame implements ActionListener
{
JTextField t1,t2,t3,t4,t5;
JLabel l1,l2,l3,l4,l5;
JButton button;
code()
{
l1=new JLabel("First value");
l2=new JLabel("Second value");
l3=new JLabel("Total");
l4=new JLabel("First value");
l5=new JLabel("Second Value");
button=new JButton("Calculate");
t1=new JTextField(10);
t2=new JTextField(10);
t3=new JTextField(10);
t4=new JTextField(10);
t5=new JTextField(10);
add(l1); add(t1); add(l4); add(t4);
add(l2); add(t2); add(l5); add(t5);
add(button); add(t3);
button.addActionListener(this);
setSize(450,300);
setLayout(new FlowLayout());
setTitle("Dumb Calculator");
}
public void actionPerformed(ActionEvent ae)
{
int a,b,c;
if(ae.getSource()==button)
{
a=Integer.parseInt(t1.getText());
b=Integer.parseInt(t2.getText());
c=a+b;
t3.setText(String.valueOf(c));
t4.setText(String.valueOf(a));
t5.setText(String.valueOf(b));
}
}
public static void main(String args[])
{
code a= new code();
a.setVisible(true);
a.setLocation(300,300);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.