I cannot get a JButton to resize...can anyone tell me what is wrong with using Button1.setBounds(1,1,2,2);...below is the class file...it is called from another file...it gives and error that I posted after the code
Code:
import java.awt.*;
import javax.swing.*; //this is required for gui layout
import java.awt.event.ActionListener; //this is required for the buttons to work
import java.awt.event.ActionEvent; //this is required for the buttons to work
public class UserInterfaceSetup implements ActionListener //This creates a new class that generates a calculator
{
//Initialize objects to be placed on the screen...and initialize the screen and panel to put stuff on
JFrame frame = new JFrame("UserInterface"); //This creates the window that the calculator is in and puts the text "calculater" in the top bar of the window (still must be placed later)
JPanel Panel1 = new JPanel(); //This creates a new panel for putting things on that is inside of the JFrame or window whatever you want to call it (still must be placed later)
//Panel1.setLayoutManager(null);
JTextArea TextEntry1 = new JTextArea(1,20); //This creates a text entry area for entering numbers for the calculator (still must be placed later)
JButton Button1 = new JButton("1"); //This creates a button with a label of 1 (still must be placed later)
Button1.setBounds(1,1,2,2);
double number1,number2,result;
int addc=0,subc=0,multic=0,divc=0;
public void ui()
{
frame.setVisible(true); //this makes the frame(window) visible on the desktop
frame.setSize(250,200); //this sets the size of the frame on the desktop in pixels
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//this tells frame what to do when close button is clicked
frame.add(Panel1); //This adds the panel to the frame on the desktop
Panel1.add(TextEntry1); //this places the text entry box on the panel
Panel1.add(Button1); //this places the button on the panel
Button1.addActionListener(this); //adds button to the list of items to watch...in "this" instance of the class
} //end of ui method
public void actionPerformed(ActionEvent e) //this method occurs if an action occurs
{
Object source = e.getSource(); //this line checks to see what the source of the action was
if(source==Button1) //if the source was button 1 then
{
TextEntry1.setText(Double.toString(result));
TextEntry1.append("1"); //append a 1 to the text field value
}
number2 = number_reader();
}// end of actionPerformed method
public double number_reader() //create a method that converts strings to integers
{
Double num1; //create a double precision number
String s; //create a string variable
s=TextEntry1.getText(); //get the text from the text entry box
num1=Double.valueOf(s); //convert the text to a double precision number and store it to num1
return num1; //pass num1 back to whatever calls this method
}
}//end of calculater_ui Class
UserInterfaceSetup.java:15: <identifier> expected
Button1.setBounds(1,1,2,2);
^
UserInterfaceSetup.java:15: illegal start of type
Button1.setBounds(1,1,2,2);
^
UserInterfaceSetup.java:15: illegal start of type
Button1.setBounds(1,1,2,2);
^
UserInterfaceSetup.java:15: illegal start of type
Button1.setBounds(1,1,2,2);
^
UserInterfaceSetup.java:15: illegal start of type
Button1.setBounds(1,1,2,2);
^
UserInterfaceSetup.java:15: package Button1 does not exist
Button1.setBounds(1,1,2,2);
^
6 errors

