I am trying to make a frame with a label and a button and cannot get it to work. Im not sure what im doing wrong.

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;


public class Program3 extends Frame implements ActionListener, WindowListener 
{
    private static final long serialVersionUID = 1L;
 	
 	Frame DispFrame;

public static void main(String[] args)	
{
	new Program3();
}
	Program3()
	{	
		//Frame
		DispFrame = new Frame("My first window");
		DispFrame.setBounds(20,20,300,900);
		DispFrame.setLayout(null);
		DispFrame.setResizable(true);
		DispFrame.pack();
		DispFrame.setVisible(true);
		DispFrame.addWindowListener(this);
		//Label
		Label OutLabel = new Label("my output");
		TextField Input = new TextField("input goes here");
		OutLabel.setBounds(50,50,100,25);
		DispFrame.add(OutLabel);
		Input.setBounds(50,100,100,25);
		DispFrame.add(Input);
		Input.addActionListener(this);		
		//Button
		Button OKButton = new Button("OK");
		DispFrame.add(OKButton);
		OKButton.addActionListener(this);
		OkButton.setLocation(200,150);
		OkButton.setSize(50,20);
		
		//Not sure where this goes....
		GridBagLayout displ = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		
		double colWeight[]={1,2,2,2,1,1,1,1,1,2};
		double rowWeight[]={1,1,1,1,1};
		int colWidth[]={1,2,2,2,1,1,1,1,2,1};
		int rowHeight[]={1,1,1,2,1}; // add rows
		displ.rowHeights=rowHeight;
		displ.colWidths=colWidth;
		displ.rowWeights=rowWeight;
		displ.colWeights=colWeight;
		
		c.anchor = GridBagConstraints.EAST; //right justify
		c.fill = GridBagConstraints.BOTH; //fill space in both directions
		c.gridwidth = 3;
		c.gridheight = 4;
		c.gridx = 1;  //tells where to go
		c.gridy = 1;   // tells it where to go
		
		displ.setConstraints(list,c);
		DisplFrame.add(List);  //Puts it on screen
		DisplFrame.add(input); //Puts it on the screen
	}		

public void windowClosing(WindowEvent e) //Window Closing
{
	stop();
}

public void windowClosed(WindowEvent e) //Window Closed
{
	system.out.println("Window closed");
}

public void stop()
{
	DispFrame.removeWindowListener(this);
	DispFrame.dispose();
}

public void windowActivated(WindowEvent e)
{
	
}

public void windowDeactivated(WindowEvent e)
{

}

public void windowOpened(WindowEvent e)
{

}

public void windowIconified(WindowEvent e) 
{

}

public void windowDeiconified(WindowEvent e) 
{

}


//************ActionPerformed***************
public void actionPerformed(ActionEvent e)

{

	String s;
		
		Object Source = e.getSource();
		if(Source == Input)  //tests which input was triggered
		{
			s = Input.getText();
			OutLabel.setText(s);
		}
else
		if(source == OkButton)
		{
			//not sure what goes here..
			
			
		}	
}
	



}

What do you mean "cannot get it to work"?

What exactly is, or is not, happening? Are you getting compiler or error messages? If so, post them, completely.

Here are the errors that i am getting when i try to run the code.

symbol : variable OkButton
location: class Program3
OkButton.setLocation(200,150);
^
\Program3.java:40: cannot find symbol
symbol : variable OkButton
location: class Program3
OkButton.setSize(50,20);
^
\Program3.java:51: cannot find symbol
symbol : variable colWidths
location: class java.awt.GridBagLayout
displ.colWidths=colWidth;
^
\Program3.java:53: cannot find symbol
symbol : variable colWeights
location: class java.awt.GridBagLayout
displ.colWeights=colWeight;
^
\Program3.java:62: cannot find symbol
symbol : variable list
location: class Program3
displ.setConstraints(list,c);
^
\Program3.java:63: cannot find symbol
symbol : variable List
location: class Program3
DisplFrame.add(List); //Puts it on screen
^
\Program3.java:63: cannot find symbol
symbol : variable DisplFrame
location: class Program3
DisplFrame.add(List); //Puts it on screen
^
\Program3.java:64: cannot find symbol
symbol : variable input
location: class Program3
DisplFrame.add(input); //Puts it on the screen
^
\Program3.java:64: cannot find symbol
symbol : variable DisplFrame
location: class Program3
DisplFrame.add(input); //Puts it on the screen
^
\Program3.java:74: package system does not exist
system.out.println("Window closed");
^
\Program3.java:117: cannot find symbol
symbol : variable Input
location: class Program3
if(Source == Input) //tests which input was triggered
^
\Program3.java:119: cannot find symbol
symbol : variable Input
location: class Program3
s = Input.getText();
^
\Program3.java:120: cannot find symbol
symbol : variable OutLabel
location: class Program3
OutLabel.setText(s);
^
\Program3.java:123: cannot find symbol
symbol : variable source
location: class Program3
if(source == OkButton)
^
\Program3.java:123: cannot find symbol
symbol : variable OkButton
location: class Program3
if(source == OkButton)
^
15 errors

thanks in advance for any help. Im really stuck here:icon_eek:

Take a look at these two lines of your code, and tell me if you see the problem.

Button OKButton = new Button("OK");
		OkButton.setLocation(200,150);

i looked over it and through all of my notes.. i do not know what is wrong

This article has been dead for over six months. Start a new discussion instead.