gary davis

Greenhorn
+ Follow
since Nov 15, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by gary davis

I created a utility file named AntoniosUtilityFile
public String reverseThisString(String toReverse)
{
return new StringBuffer(toReverse).reverse().toString();
}
}
}
I want to be able to click on a button called reverse in my main class
and it will access the information in my utility file.
public class Memo
{
public void actionPerformed(ActionEvent e)
{
if (actionCommand.equals("Reverse"))
"do something here to acces AntoniosUtilityFile"
"which will reverse the text once the reverse "
"button is clicked."
20 years ago

Originally posted by Manfred Leonhardt:
Here is my approach to it:

Regards,
Manfred.
[ November 23, 2003: Message edited by: Manfred Leonhardt ]

20 years ago
I want to create a button, so when it is clicked the text
in the JText area will be reversed.
public void actionPerformed(ActionEvent e)
{
if (actionCommand.equals("Reverse"))
else
theText.setText("Error in memo interfact.");
}
20 years ago
How can you reverse text using a button?
[ November 23, 2003: Message edited by: gary davis ]
20 years ago
I would like to know can you use a gridlayout and a borderlayout in the same class.
20 years ago
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MemoSaver2 extends JFrame implements ActionListener
{
public static final int WIDTH = 600;
public static final int HEIGHT = 300;
public static final int LINES = 10;
public static final int CHAR_PER_LINE = 40;
private JTextArea theText;
private String memo1 = "No Memo 1.";
private String memo2 = "No Memo 2.";
private String memo3 = "No Memo 3.";
private String memo4 = "No Memo 4.";

public MemoSaver2()
{
setSize(WIDTH, HEIGHT);
addWindowListener(new WindowDestroyer());
setTitle("Memo Saver");
Container contentPane = getContentPane();
contentPane.setLayout(new GridLayout(2, 3));
//this.setButton(MemoSaver2);
contentPane.setLayout(new BorderLayout());

JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.WHITE);
buttonPanel.setLayout(new FlowLayout());
JButton memo1Button = new JButton("Save Memo 1");
memo1Button.addActionListener(this);
buttonPanel.add(memo1Button);
JButton memo2Button = new JButton("Save Memo 2");
memo2Button.addActionListener(this);
buttonPanel.add(memo2Button);
JButton clearButton = new JButton("Clear");
clearButton.addActionListener(this);
buttonPanel.add(clearButton);
JButton memo3Button = new JButton("Gary Davis");
memo3Button.addActionListener(this);
buttonPanel.add(memo3Button);
JButton get1Button = new JButton("Get Memo 1");
get1Button.addActionListener(this);
buttonPanel.add(get1Button);
JButton get2Button = new JButton("Get Memo 2");
get2Button.addActionListener(this);
buttonPanel.add(get2Button);
JButton get3Button = new JButton("Get Gary Davis");
get3Button.addActionListener(this);
buttonPanel.add(get3Button);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
//contentPane.add(buttonPanel, GridLayout);
JPanel textPanel = new JPanel();
textPanel.setBackground(Color.BLUE);
theText = new JTextArea(LINES, CHAR_PER_LINE);
theText.setBackground(Color.WHITE);
textPanel.add(theText);
contentPane.add(textPanel, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent e)
{
String actionCommand = e.getActionCommand();
if (actionCommand.equals("Save Memo 1"))
{
memo1 = theText.getText();
theText.setText("Memo 1 saved.");
}
else if (actionCommand.equals("Save Memo 2"))
{
memo2 = theText.getText();
theText.setText("Memo 1 saved.");
}
else if (actionCommand.equals("Gary Davis"))
memo3 = theText.getText();
else if (actionCommand.equals("Clear"))
theText.setText("");
else if (actionCommand.equals("Get Memo 1"))
theText.setText(memo1);
else if (actionCommand.equals("Get Memo 2"))
theText.setText(memo2);
else
theText.setText("Error in memo interfact.");
}
public static void main(String[]args)
{
MemoSaver2 guiMemo = new MemoSaver2();
guiMemo.setVisible(true);
}
}
20 years ago
I am new to Java programming and I would like to know how you can use bufferedReader to read an integer. The problem with the buffredReader it is returning the wrong number or just converting the number as a binary number.
BufferedReader input = new BufferedReader(new InputStreamReader(System.in());
input = 0;
try
{
System.out.println("Enter an age");
input = input.read();
}
catch (IOException e)
{
if (input < 0)
System.out.println("Inut an Age: ");
else
System.out.println("An error has occured");
}
int correctAge = input;
20 years ago