Help me with my wierd applet please.

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2007
Posts: 2
Reputation: Notsogood.java is an unknown quantity at this point 
Solved Threads: 0
Notsogood.java Notsogood.java is offline Offline
Newbie Poster

Help me with my wierd applet please.

 
0
  #1
Sep 16th, 2007
(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)
  1. <span class="ad_notxt"><code class="inlinecode">
  2.  
  3. import java.applet.Applet;
  4. import java.awt.*;
  5. import java.util.Scanner;
  6.  
  7. public class Quote extends Applet
  8. {
  9.  
  10. public void paint(Graphics page)
  11.  
  12. {
  13.  
  14. String theirQuote;
  15.  
  16. String theAuthor;
  17.  
  18. Scanner scan = new Scanner(System.in);
  19.  
  20. page.drawString ("\"Please pass the butter.\"", 110, 70);
  21.  
  22. page.drawString ("A quote by jack padron", 110, 70);
  23.  
  24. page.drawString ("-------------------------------------------", 110, 70);
  25.  
  26. page.drawString ("Can you think of a better quote?", 110, 70);
  27.  
  28. page.drawString ("Please, write it here.", 110, 70);
  29. theirQuote = scan.nextLine();
  30.  
  31. page.drawString ("Please write the author of the quote here.", 110, 70);
  32. theAuthor = scan.nextLine();
  33.  
  34. page.drawString ("-------------------------------------------", 110, 70);
  35.  
  36. page.drawString ("Tadaaaa!!! This is the quote you entered.", 110, 70);
  37.  
  38. page.drawString ("...and the author :)", 110, 70);
  39.  
  40. page.drawString (theirQuote, 110, 70);
  41.  
  42. page.drawString (" -" + theAuthor, 110, 70);
  43. }
  44.  
  45.  
  46. }
  47. </code></span>
Last edited by Notsogood.java; Sep 16th, 2007 at 12:22 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 2
Reputation: Notsogood.java is an unknown quantity at this point 
Solved Threads: 0
Notsogood.java Notsogood.java is offline Offline
Newbie Poster

Re: Help me with my wierd applet please.

 
0
  #2
Sep 16th, 2007
If you have any questions about what I was trying to explain, just ask, of course.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 81
Reputation: lookof2day is an unknown quantity at this point 
Solved Threads: 10
lookof2day lookof2day is offline Offline
Junior Poster in Training

Re: Help me with my wierd applet please.

 
0
  #3
Sep 16th, 2007
This works absolutely file. Try it.
  1. package applet;
  2.  
  3. import java.awt.Graphics;
  4.  
  5. /**
  6.  *
  7.  * @author desperado
  8.  */
  9. public class JQuote extends javax.swing.JApplet {
  10.  
  11. /** Initializes the applet JQuote */
  12. public void init() {
  13. try {
  14. java.awt.EventQueue.invokeAndWait(new Runnable() {
  15. public void run() {
  16. initComponents();
  17. }
  18. });
  19. } catch (Exception ex) {
  20. ex.printStackTrace();
  21. }
  22. }
  23.  
  24. /** This method is called from within the init() method to
  25.   * initialize the form.
  26.   * WARNING: Do NOT modify this code. The content of this method is
  27.   * always regenerated by the Form Editor.
  28.   */
  29. // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
  30. private void initComponents() {
  31.  
  32. jLabel1 = new javax.swing.JLabel();
  33. jSeparator1 = new javax.swing.JSeparator();
  34. jLabel2 = new javax.swing.JLabel();
  35. txtQuote = new javax.swing.JTextField();
  36. ok = new javax.swing.JButton();
  37. jSeparator2 = new javax.swing.JSeparator();
  38.  
  39. jLabel1.setText("Please Pass The Butter. -- A quote by Jack Pardon");
  40.  
  41. jLabel2.setText("Enter Your Quote");
  42.  
  43. ok.setText("Ok");
  44. ok.addActionListener(new java.awt.event.ActionListener() {
  45. public void actionPerformed(java.awt.event.ActionEvent evt) {
  46. okActionPerformed(evt);
  47. }
  48. });
  49.  
  50. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  51. getContentPane().setLayout(layout);
  52. layout.setHorizontalGroup(
  53. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  54. .addGroup(layout.createSequentialGroup()
  55. .addContainerGap()
  56. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  57. .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
  58. .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
  59. .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 355, javax.swing.GroupLayout.PREFERRED_SIZE)
  60. .addGroup(layout.createSequentialGroup()
  61. .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
  62. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  63. .addComponent(txtQuote, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
  64. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  65. .addComponent(ok)))
  66. .addContainerGap())
  67. );
  68. layout.setVerticalGroup(
  69. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  70. .addGroup(layout.createSequentialGroup()
  71. .addGap(26, 26, 26)
  72. .addComponent(jLabel1)
  73. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  74. .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
  75. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  76. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  77. .addComponent(ok)
  78. .addComponent(jLabel2)
  79. .addComponent(txtQuote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  80. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  81. .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
  82. .addContainerGap(189, Short.MAX_VALUE))
  83. );
  84. }// </editor-fold>
  85.  
  86. private void okActionPerformed(java.awt.event.ActionEvent evt) {
  87. // TODO add your handling code here:
  88. Graphics g = this.getGraphics();
  89. g.drawString(txtQuote.getText(), 110, 70);
  90. }
  91.  
  92.  
  93. // Variables declaration - do not modify
  94. private javax.swing.JLabel jLabel1;
  95. private javax.swing.JLabel jLabel2;
  96. private javax.swing.JSeparator jSeparator1;
  97. private javax.swing.JSeparator jSeparator2;
  98. private javax.swing.JButton ok;
  99. private javax.swing.JTextField txtQuote;
  100. // End of variables declaration
  101.  
  102. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC