• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Button Problems

 
Chase Becicka
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble with my program, I have been compiling it repeatedly and has all work fine until I wrote the class attempting to acess my action listener for the calculation this is when the errors have started. I have remade all my buttons and class several times to make sure datatypes do not conflict but the same errors continue to occure so please exaime my source code and help me debug

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Character.*;

public class upperTolower extends JFrame
{
private static final int WIDTH = 400;
private static final int HEIGHT = 300;

private JLabel upperCaseL, lowerCaseL;
private JTextField upperCaseTF, lowerCaseTF;
private JButton calcUpperB, calcLowerB, exitB;
ExitButtonHandler exitHandler;
CalculateLButtonHandler calculateLHandler;
CalculateUButtonHandler calculateUHandler;

public upperTolower()
{
setTitle("Character Conversion");

upperCaseL = new JLabel("Enter Upper Case Values: ", SwingConstants.CENTER);
lowerCaseL = new JLabel("Enter Lower Case Values: ", SwingConstants.CENTER);

upperCaseTF = new JTextField(15);
lowerCaseTF = new JTextField(15);

calcUpperB = new JButton("Upper");
calculateUHandler = new CalculateUButtonHandler();
calcUpperB.addActionListener(calculateUHandler);

calcLowerB = new JButton("Lower");
calculateLHandler = new CalculateLButtonHandler();
calcLowerB.addActionListener(calculateLHandler);

exitB = new JButton("Exit");
exitHandler = new ExitButtonHandler();
exitB.addActionListener(exitHandler);

Container pane = getContentPane();
pane.setLayout(new GridLayout(3,2));

pane.add(upperCaseL);
pane.add(upperCaseTF);
pane.add(lowerCaseL);
pane.add(lowerCaseTF);
pane.add(calcUpperB);
pane.add(calcLowerB);
pane.add(exitB);

setSize(WIDTH,HEIGHT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}



public class CalculateUButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
char LowerCaseValues, UpperCaseValues;

LowerCaseValues = Character.parseChar(lowerCaseTF.getText());

upperCaseTF.setText(""+ Character.toUpperCase(+LowerCaseValues));

}
}


public static void main(String[] args)
{
upperTolower upperTolowerObject = new upperTolower();
}
}
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Care to share with us the errors you are having?
 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chase Becicka:

public class CalculateUButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
char LowerCaseValues, UpperCaseValues;

LowerCaseValues = Character.parseChar(lowerCaseTF.getText());

upperCaseTF.setText(""+ Character.toUpperCase(+LowerCaseValues));

}
}




This doesn't look like it would compile. I can't find a parseChar method for Character under java1.4.2. Are you trying to just switch the case of all the chars?

You don't need the "" either. The +LowerCaseValues doesn't make sense.

Just some background hints, you might want to ensure all your class names start with a capital letter. Also, variable names might be better off starting with a lowercase letter. Other programmers will be accustomed to using the case of the first letter to differentiate between classes, vars, and method names.

HTH,
Aaron R>
 
Chase Becicka
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Documents and Settings\diadem\Desktop\upperTolower.java:14: cannot resolve symbol
symbol : class ExitButtonHandler
location: class upperTolower
ExitButtonHandler exitHandler;
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:15: cannot resolve symbol
symbol : class CalculateLButtonHandler
location: class upperTolower
CalculateLButtonHandler calculateLHandler;
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:33: cannot resolve symbol
symbol : class CalculateLButtonHandler
location: class upperTolower
calculateLHandler = new CalculateLButtonHandler();
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:37: cannot resolve symbol
symbol : class ExitButtonHandler
location: class upperTolower
exitHandler = new ExitButtonHandler();
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:64: cannot resolve symbol
symbol : method parseChar (java.lang.String)
location: class java.lang.Character
LowerCaseValues = Character.parseChar(lowerCaseTF.getText());
^
C:\Documents and Settings\diadem\Desktop\upperTolower.java:66: toUpperCase(char) in java.lang.Character cannot be applied to (int)
upperCaseTF.setText(""+ Character.toUpperCase(+LowerCaseValues));


Here are my errors
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason for the 1st 5 errors you listed are probably because these classes that your are trying to make new objects from don't exist. And then you try and use these classes in your code. You might need to check and see if your teacher has these or maybe these are what you are supposed to create for your assignment.
 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is starting to sound more like a java programming issue than a graphics one.

As Gregg mentioned, you are missing some classes, but it appears you could do a little rewriting and dispense with them. Unless they are required by the course? you are taking.

What did your prgm look like before you got the compile errors?

Regards,
Aaron R>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic