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..
}
}
}