In my following program, how do I have numbers entered into the TextArea that when I click the JButton the numbers add up and are displayed in the TextField above the JButton ??? -
-
-
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
-
public class Main extends JFrame
-
{
-
-
private JTextField jTextField1;
-
private JTextArea jTextArea1;
-
private JScrollPane jScrollPane1;
-
private JButton jButton1;
-
private JPanel contentPane;
-
-
-
-
public Main()
-
{
-
super();
-
initializeComponent();
-
-
this.setVisible(true);
-
}
-
-
-
private void initializeComponent()
-
{
-
jTextField1 = new JTextField();
-
jTextArea1 = new JTextArea();
-
jScrollPane1 = new JScrollPane();
-
jButton1 = new JButton();
-
contentPane = (JPanel)this.getContentPane();
-
-
-
jTextField1.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e)
-
{
-
jTextField1_actionPerformed(e);
-
}
-
-
});
-
-
jScrollPane1.setViewportView(jTextArea1);
-
-
jButton1.setText("obtain the sum");
-
jButton1.addActionListener(new ActionListener() {
-
public void actionPerformed(ActionEvent e)
-
{
-
jButton1_actionPerformed(e);
-
}
-
-
});
-
-
contentPane.setLayout(null);
-
addComponent(contentPane, jTextField1, 310,59,225,45);
-
addComponent(contentPane, jScrollPane1, 17,26,266,298);
-
addComponent(contentPane, jButton1, 340,225,156,31);
-
-
this.setTitle("Main - extends JFrame");
-
this.setLocation(new Point(0, 0));
-
this.setSize(new Dimension(573, 440));
-
}
-
-
-
private void addComponent(Container container,Component c,int x,int y,int width,int height)
-
{
-
c.setBounds(x,y,width,height);
-
container.add(c);
-
}
-
-
-
private void jTextField1_actionPerformed(ActionEvent e)
-
{
-
System.out.println("\njTextField1_actionPerformed(ActionEvent e) called.");
-
-
-
}
-
-
private void jButton1_actionPerformed(ActionEvent e)
-
{
-
System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
-
-
-
}
-
-
-
1 2174
Divide the problem into steps.
1. Capture the button press event.
2. Get the input.
3. Process the input.
3b. Convert the input into integers from string.
4. Display the output.
Which of these steps are you specifically having trouble with?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ravi Tallury |
last post by:
Hi
We are having issues with our application, certain portions of it stop
responding while the rest of the application is fine. I am attaching
the Java Core dump. If someone can let me know what...
|
by: ptaz |
last post by:
Hi I'm trying to run a web page but I get the following error. Ca
anyone please tell me a solution to this.
Thanks
Ptaz
HTTP Status 500 -
type Exception report
|
by: DrUg13 |
last post by:
In java, this seems so easy. You need a new object
Object test = new Object() gives me exactly what I want.
could someone please help me understand the different ways to do the
same thing in...
|
by: mailkhurana |
last post by:
Hii ,
I am trying to use a type 2 driver to connect to DB2 0n AIX 5
I have a small java test to class to establish a conneciton with the db
.. I am NOT using WAS or any appserver
When I try to...
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej...
|
by: Mark Fink |
last post by:
I wrote a Jython class that inherits from a Java class and (thats the
plan) overrides one method. Everything should stay the same.
If I run this nothing happens whereas if I run the Java class it...
|
by: jaywak |
last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build...
|
by: jaimemartin |
last post by:
hello,
I want to validate an xml by means of a schema (xsd). To do that first of all I´m using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in...
|
by: oll3i |
last post by:
package library.common;
import java.sql.ResultSet;
public interface LibraryInterface {
public ResultSet getBookByAuthor(String author);
public ResultSet getBookByName(String name);
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |