(I'm not even close to being sure that this is even a valid approach to what I want to accomplish. Still, all input is welcome. What I was trying to do was create an applet that reads):

"Please pass the butter."
A quote by jack padron
-------------------------------------------
Can you think of a better quote?
Please, write it here.

(then, of course the user writes his or her quote. After that, my program would print):

Please write the author of the quote here.

(After entering the author, it would print the quote that the user wrote and the author underneath.I coded it perfectly as a regular java program that was unappletatized. Then I wanted to put it all into applet form... This is where I'm sure I messed up. My new weird Applet program [a modified version of the original non-applet program] doesn't work. (The original was all System.out.println(); not page.draw) I'm sure that it's laced with mistakes, but there is only one runtime error and it is the classic

"java.lang.NoSuchMethodError: main Exception in thread "main" "

(Here is my program)

import java.applet.Applet;
import java.awt.*;
import java.util.Scanner;

public class Quote extends Applet 
{

    public void paint(Graphics page)

        {

            String theirQuote; 

            String theAuthor;

            Scanner scan = new Scanner(System.in); 

            page.drawString ("\"Please pass the butter.\"", 110, 70);

            page.drawString ("A quote by jack padron", 110, 70);

            page.drawString ("-------------------------------------------", 110, 70);

            page.drawString ("Can you think of a better quote?", 110, 70);

            page.drawString ("Please, write it here.", 110, 70);
            theirQuote = scan.nextLine();

            page.drawString ("Please write the author of the quote here.", 110, 70); 
            theAuthor = scan.nextLine();

            page.drawString ("-------------------------------------------", 110, 70);

            page.drawString ("Tadaaaa!!! This is the quote you entered.", 110, 70);

            page.drawString ("...and the author :)", 110, 70);

            page.drawString (theirQuote, 110, 70);

            page.drawString ("         -" + theAuthor, 110, 70);
    }


}

Edited 3 Years Ago by pyTony: fixed formatting

This works absolutely file. Try it.

package applet;

import java.awt.Graphics;

/**
 *
 * @author  desperado
 */
public class JQuote extends javax.swing.JApplet {
    
    /** Initializes the applet JQuote */
    public void init() {
        try {
            java.awt.EventQueue.invokeAndWait(new Runnable() {
                public void run() {
                    initComponents();
                }
            });
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        txtQuote = new javax.swing.JTextField();
        ok = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();

        jLabel1.setText("Please Pass The Butter. -- A quote by Jack Pardon");

        jLabel2.setText("Enter Your Quote");

        ok.setText("Ok");
        ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 355, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtQuote, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ok)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ok)
                    .addComponent(jLabel2)
                    .addComponent(txtQuote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(189, Short.MAX_VALUE))
        );
    }// </editor-fold>

private void okActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    Graphics g = this.getGraphics();
    g.drawString(txtQuote.getText(), 110, 70);
}
    
    
    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JButton ok;
    private javax.swing.JTextField txtQuote;
    // End of variables declaration
    
}
This article has been dead for over six months. Start a new discussion instead.