| | |
Help me with my wierd applet please.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Solved Threads: 0
(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: mainException in thread "main" ")
(Here is my program)
"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: mainException in thread "main" ")
(Here is my program)
Java Syntax (Toggle Plain Text)
<span class="ad_notxt"><code class="inlinecode"> 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); } } </code></span>
Last edited by Notsogood.java; Sep 16th, 2007 at 12:22 am.
•
•
Join Date: Aug 2007
Posts: 81
Reputation:
Solved Threads: 10
This works absolutely file. Try it.
Java Syntax (Toggle Plain Text)
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 }
![]() |
Similar Threads
- Java Applet viewer blinks everytime the init method is used. (Java)
- Java Game Applet Too Small (Java)
- Problem with Yahoo chat applet. (Windows NT / 2000 / XP)
- help!! My applet can't run... Urgent!! (Java)
- where to get the java applet? (Web Browsers)
- applet crashed (Windows NT / 2000 / XP)
- Applet or Application? (Java)
Other Threads in the Java Forum
- Previous Thread: Not Writing to Text File
- Next Thread: Extract field from text file
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows





