import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class MyTemplateGui extends JFrame implements ActionListener
{
private static final int FRAME_WIDTH = 500;
private static final int FRAME_HEIGHT = 500;
private static final int FRAME_X_ORIGIN = 500;
private static final int FRAME_Y_ORIGIN = 500;
private static final int BUTTON_WIDTH = 80;
private static final int BUTTON_HEIGHT = 30;
private JLabel promptText1;
private JTextArea textArea;
private JButton okButton;
private JButton cancelButton;
private JTextField inputLine;
public static void main(String[] args)
{
MyTemplateGui frame = new MyTemplateGui();
frame.setVisible(true);
}
public MyTemplateGui( )
{
super("Graphics Template Title");
Container contentPane = getContentPane();
contentPane.setLayout(null);
// setTitle ("Gab < kevin cone");
setSize (FRAME_WIDTH, FRAME_HEIGHT);
setLocation (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
// Color c = new Color(0,200,0); //rgb
// contentPane.setBackground(c);
contentPane.setBackground(Color.yellow);
okButton = new JButton("Ok");
okButton.setBounds(70, 125, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(okButton);
okButton.addActionListener(this);
cancelButton = new JButton("Cancel");
cancelButton.setBounds(160,125, BUTTON_WIDTH, BUTTON_HEIGHT);
contentPane.add(cancelButton);
cancelButton.addActionListener(this);
promptText1 = new JLabel();
promptText1.setText("Text appears here...");
promptText1.setBounds(30, 20, 150, 25); // 30 from left, 20 from top, 150 length, 25 height
promptText1.setForeground(Color.black);
contentPane.add(promptText1);
inputLine = new JTextField();
inputLine.setBounds(30, 50, 150, 25);
contentPane.add(inputLine);
inputLine.addActionListener(this);
textArea = new JTextArea();
textArea.setBounds(30, 200, 430, 225);
textArea.setText("The quick brown fox...\nsome more text");
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
contentPane.add(textArea);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent event)
{
JButton clickedButton = (JButton) event.getSource();
if(clickedButton == okButton)
{
String inputString = "";
inputString = inputLine.getText();
textArea.append("\n" + inputString);
}
if(clickedButton == cancelButton)
{
System.exit(0);
}
}
}