delphi3
asked on
Show data in a textArea
Hi All,
I have a demo program below that runs exactly as I want it to with a
System in and out, and now in the second program below I want to move up appearance
wise to show textFields and textArea within a frame so that
the user can type the needed input data in a TextField and the
program show the output in the TextArea.
I think that maybe I have the necessary textfields to get user to enter the name and age but I cannot get the name and age to show into the text area.
I appreciate your help in this matter. This is not homework.
Delphi3
package systeminouttotxtfieldinout ;
import java.io.*;
public class textSystemInOut {
public textSystemInOut() {
}
public static void main(String[] args) {
InputStreamReader keyboard = new InputStreamReader(System.i n);
BufferedReader input = new BufferedReader(keyboard);
try {
System.out.println("Enter your name ");
System.out.print(" ");
String name = input.readLine();
System.out.println("Your Age ");
String age = input.readLine();
int iage = (int) Integer.parseInt(age);
System.out.println("My Name is " + name + " and twice my Age Is " +
iage * 2);
System.out.println("Thank you");
}
catch (Exception e) {
System.out.println("error getting data");
}
}
}
package systeminouttotxtfieldinout ;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
public class framedTextFieldInOut
extends JPanel {
String name;
String age;
int iage;
private BarPanel barPanel;
public static JTextField nameField = null;
public static JTextField ageField = null;
public static JTextArea ShowInArea = null;
private Action startAction = new AbstractAction("Process") {
public void actionPerformed(ActionEven t displayData) {
}
};
public framedTextFieldInOut() {
setLayout(new BorderLayout());
JPanel dataPane = new JPanel();
barPanel = new BarPanel();
barPanel.setBorder(
BorderFactory.createLineBo rder(getFo reground() , 2));
add(barPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
add(buttonPanel, BorderLayout.SOUTH);
buttonPanel.add(new JButton(startAction));
add(dataPane, BorderLayout.CENTER);
dataPane.add(new JLabel("Name : "));
nameField = new JTextField(10);
dataPane.add(nameField);
nameField.setText(name);
nameField.setEnabled(false );
nameField.addFocusListener (new FocusAdapter() {
public void focusLost(FocusEvent e) {
nameField.selectAll();
name = nameField.getText();
}
});
dataPane.add(new JLabel("Age : "));
ageField = new JTextField(10);
dataPane.add(ageField);
ageField.setText(age);
ageField.setEnabled(false) ;
ageField.addFocusListener( new FocusAdapter() {
public void focusLost(FocusEvent e) {
ageField.selectAll();
age = ageField.getText();
int iage = (int) Integer.parseInt(age);
}
});
dataPane.add(new JLabel("Summary Report :"));
dataPane.add(new JTextArea(10, 30));
// Show ??????
}
public static void main(String[] args) {
javax.swing.JFrame frame = new JFrame();
frame.setTitle("Conversion To Frame");
frame.setDefaultCloseOpera tion(JFram e.EXIT_ON_ CLOSE);
frame.setBounds(200, 200, 350, 400);
frame.getContentPane().add (new framedTextFieldInOut());
frame.validate();
frame.show();
try {
UIManager.setLookAndFeel(U IManager.g etSystemLo okAndFeelC lassName() );
}
catch (Exception e) {
e.printStackTrace();
}
new framedTextFieldInOut();
}
}
class BarPanel
extends JPanel {
}
I have a demo program below that runs exactly as I want it to with a
System in and out, and now in the second program below I want to move up appearance
wise to show textFields and textArea within a frame so that
the user can type the needed input data in a TextField and the
program show the output in the TextArea.
I think that maybe I have the necessary textfields to get user to enter the name and age but I cannot get the name and age to show into the text area.
I appreciate your help in this matter. This is not homework.
Delphi3
package systeminouttotxtfieldinout
import java.io.*;
public class textSystemInOut {
public textSystemInOut() {
}
public static void main(String[] args) {
InputStreamReader keyboard = new InputStreamReader(System.i
BufferedReader input = new BufferedReader(keyboard);
try {
System.out.println("Enter your name ");
System.out.print(" ");
String name = input.readLine();
System.out.println("Your Age ");
String age = input.readLine();
int iage = (int) Integer.parseInt(age);
System.out.println("My Name is " + name + " and twice my Age Is " +
iage * 2);
System.out.println("Thank you");
}
catch (Exception e) {
System.out.println("error getting data");
}
}
}
package systeminouttotxtfieldinout
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
public class framedTextFieldInOut
extends JPanel {
String name;
String age;
int iage;
private BarPanel barPanel;
public static JTextField nameField = null;
public static JTextField ageField = null;
public static JTextArea ShowInArea = null;
private Action startAction = new AbstractAction("Process") {
public void actionPerformed(ActionEven
}
};
public framedTextFieldInOut() {
setLayout(new BorderLayout());
JPanel dataPane = new JPanel();
barPanel = new BarPanel();
barPanel.setBorder(
BorderFactory.createLineBo
add(barPanel, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
add(buttonPanel, BorderLayout.SOUTH);
buttonPanel.add(new JButton(startAction));
add(dataPane, BorderLayout.CENTER);
dataPane.add(new JLabel("Name : "));
nameField = new JTextField(10);
dataPane.add(nameField);
nameField.setText(name);
nameField.setEnabled(false
nameField.addFocusListener
public void focusLost(FocusEvent e) {
nameField.selectAll();
name = nameField.getText();
}
});
dataPane.add(new JLabel("Age : "));
ageField = new JTextField(10);
dataPane.add(ageField);
ageField.setText(age);
ageField.setEnabled(false)
ageField.addFocusListener(
public void focusLost(FocusEvent e) {
ageField.selectAll();
age = ageField.getText();
int iage = (int) Integer.parseInt(age);
}
});
dataPane.add(new JLabel("Summary Report :"));
dataPane.add(new JTextArea(10, 30));
// Show ??????
}
public static void main(String[] args) {
javax.swing.JFrame frame = new JFrame();
frame.setTitle("Conversion
frame.setDefaultCloseOpera
frame.setBounds(200, 200, 350, 400);
frame.getContentPane().add
frame.validate();
frame.show();
try {
UIManager.setLookAndFeel(U
}
catch (Exception e) {
e.printStackTrace();
}
new framedTextFieldInOut();
}
}
class BarPanel
extends JPanel {
}
ASKER
JAVATM,
I tried to place it in several locations within the program.
And it had no benefit.
Can we assume there is already a button ("Process") that is on the above form and it sits there with no action. Can you please include it into your gift and then locate it within the program or is that not possible?
Delphi3
I tried to place it in several locations within the program.
And it had no benefit.
Can we assume there is already a button ("Process") that is on the above form and it sits there with no action. Can you please include it into your gift and then locate it within the program or is that not possible?
Delphi3
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Javatm,
Thanks so much. Great job!!!
Your gift solves my problem for this part of sloshing through the details. These details are trying to convert a program that makes a tcp server and a tcp client that is constructed in a format using String name = input.readLine();and System.out.println(name); to a new framed version.
Thanks again.
Delphi3
Thanks so much. Great job!!!
Your gift solves my problem for this part of sloshing through the details. These details are trying to convert a program that makes a tcp server and a tcp client that is constructed in a format using String name = input.readLine();and System.out.println(name); to a new framed version.
Thanks again.
Delphi3
:) Glad to help . . .
You just need to create a JButton and set the action listener like :
JButton b1 = new JButton("Display");
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEven
{
String s1 = nameField.getText();
String s2 = ageField.getText();
ShowInArea.setText(""+s1+"
// If you want to append you can use this :
// ShowInArea.append(""+s1+"\
}
});
Hope it helps . . .
JAVATM