Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java Applet Coding Help?

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Applet Coding Help?

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


  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Applet Coding Help?

    I admire your courage. You are pretty new to this, yet you coded well

    Quote Originally Posted by Drag01 View Post
    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
     
    }
     
    }

Similar Threads

  1. Java coding help
    By Javalover1 in forum The Cafe
    Replies: 0
    Last Post: April 12th, 2010, 08:11 PM
  2. Need help with java applet game.
    By vlan in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 10th, 2010, 04:18 AM
  3. Help with 1st Java applet game!
    By Sneak in forum Java Applets
    Replies: 0
    Last Post: November 28th, 2009, 11:20 AM
  4. Designing RLC Circuit using Java Applet
    By syxxpac316 in forum Java Applets
    Replies: 6
    Last Post: May 13th, 2009, 04:26 PM
  5. 15, Loves ICT, learning Java coding.
    By Sergant Mitch in forum Member Introductions
    Replies: 1
    Last Post: September 20th, 2008, 09:40 AM