I admire your courage. You are pretty new to this, yet you coded well
Originally Posted by
Drag01
Ok, so i filled out most of the codes that was instructed to code, and i hope i did it right, im still pretty new to all this. Anyways im just confused on how to code the last two "else if" codings down there. Can anyone help me on that? Did i also code everything correctly? thanks in advance. Here is my code:
import java.applet.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Lab7 extends JApplet implements ActionListener {
JLabel inputLabel;
//(0.5 pt) Create a label for outputLabel
JLabel outputLabel;
JTextField inputTxtFd;
//(0.5 pt) Create a text field for outputTxtFd
JTextField outputTxtFd;
JButton enableBnt;
// (1 pt)Create a button for disableBnt
// Create a button for clearBnt
JButton disableBnt;
JButton clearBnt;
JPanel dataPanel;
// (0.5 pt) Create a panel for buttonPanel
JPanel buttonPanel;
boolean echoEnabled;
public void init() {
dataPanel = new JPanel();
inputLabel = new JLabel("Type your input");
inputTxtFd = new JTextField(20);
// (1 pt) Create the output label, outputLabel with value “Echo”
// Create the output text field, outputTxtFd with 20 space
outputLabel = new JLabel("Echo");
outputTxtFd = new JTextField(20);
outputTxtFd.setEnabled(false);
dataPanel.add(inputLabel);
dataPanel.add(inputTxtFd);
// (1 pt) Add the output label, outputLabel, to the dataPanel
// Add the output text field, outputTxtFd, to the dataPanel
inputTxtFd.setEnabled(false);
dataPanel.add(outputLabel);
dataPanel.add(outputTxtFd);
// (0.5 pt) Create button panel, named buttonPanel;
// see code for creating data panel
JPanel buttonPanel = new JPanel();
enableBnt= new JButton("Enable");
//(1 pt) Create the disable button, disableBnt with value “Disable”
// Create the clear button, clearBnt with value “Clear”
disableBnt = new JButton("Disable");
clearBnt = new JButton("Clear");
buttonPanel.add(enableBnt);
// (1 pt) Add the disable button, disableBnt, to the buttonPanel
// Add the clear button, clearBnt, to the buttonPanel
buttonPanel.add(disableBnt);
buttonPanel.add(clearBnt);
getContentPane().add(dataPanel, BorderLayout.NORTH);
// (0.5 pt) Add the button panel to the applet, at SOUTH
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
enableBnt.addActionListener(this);
// (1 pt) Listen to the disableBnt
// Listen to the clearBnt
disableBnt.addActionListener(this);
clearBnt.addActionListener(this);
inputTxtFd.addKeyListener(new KeyEventHandler());
}
public void start() {
clearBnt.setEnabled(false);
enableBnt.setEnabled(false);
echoEnabled= true;
inputTxtFd.setText("");
outputTxtFd.setText("");
}
class KeyEventHandler extends KeyAdapter {
public void keyReleased(KeyEvent evt) {
if(echoEnabled) {
outputTxtFd.setText(inputTxtFd.getText());
clearBnt.setEnabled(true);
}
}
}
public void actionPerformed(ActionEvent event) {
Object sourceObject = event.getSource();
if (sourceObject == enableBnt) {
echoEnabled = true;
enableBnt.setEnabled(false);
disableBnt.setEnabled(true);
}
else if (
//(0.5 pt) disable button is clicked) {
// (0.5 pt) fill in code
}
else if (//(0.5 pt)clear button is clicked) {
// (0.5 pt) clear the text fields
// (0.5 pt) disable the Clear button
}
}