944,149 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 316
  • Java RSS
Nov 5th, 2009
0

Error on repairing program

Expand Post »
Hi all.
pls help me.I repair a program for my need.At that time Text are not appear.Original progarm is here.
Java Syntax (Toggle Plain Text)
  1.  
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.Rectangle;
  5. import java.awt.Toolkit;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.MouseAdapter;
  9. import java.awt.event.MouseEvent;
  10. import java.io.IOException;
  11. import javax.swing.JFrame;
  12. import javax.swing.JLabel;
  13. import javax.swing.JPanel;
  14. import javax.swing.Timer;
  15.  
  16. public class MarqueeFrame extends JFrame implements ActionListener {
  17.  
  18. private Timer timer;
  19. private MarqueePanel marqueePanel;
  20.  
  21. // Timer Event Handler
  22. public void actionPerformed(ActionEvent e) {
  23. // move the Label in the MarqueePanel
  24. marqueePanel.moveLabel();
  25. }
  26.  
  27. public MarqueeFrame() {
  28.  
  29. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  30. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31. setSize(d.width,d.height);
  32. setTitle("Marquee");
  33. setResizable(false);
  34.  
  35. timer = new Timer(150, this);
  36. marqueePanel = new MarqueePanel(timer);
  37. add(marqueePanel);
  38. timer.start();
  39.  
  40. }
  41.  
  42. public static void main(String[] args) {
  43. new MarqueeFrame().setVisible(true);
  44. }
  45.  
  46. }
  47.  
  48.  
  49. class MarqueePanel extends JPanel {
  50. private int xLoc, yLoc;
  51. private Dimension dimension;
  52. private JLabel googleLabel;
  53. private JLabel yahooLabel;
  54. private Timer timer;
  55.  
  56. public MarqueePanel(final Timer timer) {
  57. this.timer = timer;
  58. setLayout(null);
  59. dimension = Toolkit.getDefaultToolkit().getScreenSize();
  60. xLoc = dimension.width;
  61. yLoc = 0;
  62. googleLabel = new JLabel("Google");
  63. googleLabel.setForeground(Color.BLUE);
  64. yahooLabel = new JLabel("Yahoo");
  65. yahooLabel.setForeground(Color.RED);
  66. googleLabel.addMouseListener(new MouseAdapter() {
  67.  
  68. public void mouseClicked(MouseEvent e) {
  69. if (e.getClickCount() > 0) {
  70. try {
  71. Runtime.getRuntime().exec("cmd.exe /c start http://www.google.com");
  72. } catch (IOException ex) {
  73. System.out.println(ex.getMessage());
  74. }
  75. }
  76. }
  77.  
  78. public void mouseEntered(MouseEvent e) {
  79. timer.stop();
  80. }
  81.  
  82. public void mouseExited(MouseEvent e) {
  83. timer.start();
  84. }
  85.  
  86. });
  87. yahooLabel.addMouseListener(new MouseAdapter() {
  88.  
  89. public void mouseClicked(MouseEvent e) {
  90. if (e.getClickCount() > 0) {
  91. try {
  92. Runtime.getRuntime().exec("cmd.exe /c start http://www.yahoo.com");
  93. } catch (IOException ex) {
  94. System.out.println(ex.getMessage());
  95. }
  96. }
  97. }
  98.  
  99. public void mouseEntered(MouseEvent e) {
  100. timer.stop();
  101. }
  102.  
  103. public void mouseExited(MouseEvent e) {
  104. timer.start();
  105. }
  106. });
  107. add(googleLabel);
  108. add(yahooLabel);
  109. moveLabel();
  110. }
  111.  
  112. public void moveLabel() {
  113.  
  114. Rectangle r = new Rectangle();
  115.  
  116. r.x = xLoc;
  117. r.y = yLoc;
  118. Dimension size = googleLabel.getPreferredSize();
  119. r.width = size.width;
  120. r.height = size.height;
  121. googleLabel.setBounds(r);
  122.  
  123. // Append the Width of First Label to avoid overlapping
  124. r.x += r.width + 5;
  125. size = yahooLabel.getPreferredSize();
  126. r.width = size.width;
  127. r.height = size.height;
  128. yahooLabel.setBounds(r);
  129.  
  130. xLoc -= 5;
  131. if (xLoc < 0 )
  132. xLoc = dimension.width;
  133. }
  134.  
  135.  
  136.  
  137. }

I repaired this as looping style.At that time.marquee text is not appear.Pls help me.Where I wrong?Thank in advance.Here is repaired program
Java Syntax (Toggle Plain Text)
  1.  
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.Rectangle;
  5. import java.awt.Toolkit;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.MouseAdapter;
  9. import java.awt.event.MouseEvent;
  10. import java.io.IOException;
  11. import javax.swing.JFrame;
  12. import javax.swing.JLabel;
  13. import javax.swing.JPanel;
  14. import javax.swing.Timer;
  15.  
  16. public class MarqueeFrame extends JFrame implements ActionListener {
  17.  
  18. private Timer timer;
  19. private MarqueePanel marqueePanel;
  20.  
  21. // Timer Event Handler
  22. public void actionPerformed(ActionEvent e) {
  23. // move the Label in the MarqueePanel
  24. marqueePanel.moveLabel();
  25. }
  26.  
  27. public MarqueeFrame() {
  28.  
  29. Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
  30. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  31. setSize(d.width,d.height);
  32. setTitle("Marquee");
  33. setResizable(true);
  34.  
  35. timer = new Timer(150, this);
  36. marqueePanel = new MarqueePanel(timer);
  37. add(marqueePanel);
  38. timer.start();
  39.  
  40. }
  41.  
  42. public static void main(String[] args) {
  43. new MarqueeFrame().setVisible(true);
  44. }
  45.  
  46. }
  47.  
  48.  
  49. class MarqueePanel extends JPanel {
  50. private int xLoc, yLoc;
  51. private Dimension dimension;
  52. private JLabel googleLabel;
  53. private JLabel yahooLabel;
  54. private Timer timer;
  55. private JLabel stringlbl;
  56. String stringlabel[][];
  57.  
  58. public MarqueePanel(final Timer timer) {
  59. this.timer = timer;
  60. setLayout(null);
  61. dimension = Toolkit.getDefaultToolkit().getScreenSize();
  62. xLoc = dimension.width;
  63. yLoc = 0;
  64. stringlabel =new String[2][2];
  65. stringlabel[0][0] = "Google";
  66. stringlabel[0][1] = "http://www.google.com";
  67. stringlabel[1][0] = "Yahoo";
  68. stringlabel[1][1] = "http://www.yahoo.com";
  69. for(int i=0;i<stringlabel.length;i++)
  70. {
  71. stringlbl = new JLabel(stringlabel[i][0]);
  72. stringlbl.setForeground(Color.BLUE);
  73. final String link = stringlabel[i][1];
  74. stringlbl.addMouseListener(new MouseAdapter() {
  75.  
  76. public void mouseClicked(MouseEvent e) {
  77. if (e.getClickCount() > 0) {
  78. try {
  79. Runtime.getRuntime().exec("cmd.exe /c start "+link);
  80. } catch (IOException ex) {
  81. System.out.println(ex.getMessage());
  82. }
  83. }
  84. }
  85.  
  86. public void mouseEntered(MouseEvent e) {
  87. timer.stop();
  88. }
  89.  
  90. public void mouseExited(MouseEvent e) {
  91. timer.start();
  92. }
  93.  
  94. });
  95. add(stringlbl);
  96. moveLabel();
  97. }
  98. /*googleLabel = new JLabel("Google");
  99.   googleLabel.setForeground(Color.BLUE);
  100.   yahooLabel = new JLabel("Yahoo");
  101.   yahooLabel.setForeground(Color.RED);
  102.   googleLabel.addMouseListener(new MouseAdapter() {
  103.  
  104.   public void mouseClicked(MouseEvent e) {
  105.   if (e.getClickCount() > 0) {
  106.   try {
  107.   Runtime.getRuntime().exec("cmd.exe /c start http://www.google.com");
  108.   } catch (IOException ex) {
  109.   System.out.println(ex.getMessage());
  110.   }
  111.   }
  112.   }
  113.  
  114.   public void mouseEntered(MouseEvent e) {
  115.   timer.stop();
  116.   }
  117.  
  118.   public void mouseExited(MouseEvent e) {
  119.   timer.start();
  120.   }
  121.  
  122.   });
  123.   yahooLabel.addMouseListener(new MouseAdapter() {
  124.  
  125.   public void mouseClicked(MouseEvent e) {
  126.   if (e.getClickCount() > 0) {
  127.   try {
  128.   Runtime.getRuntime().exec("cmd.exe /c start http://www.yahoo.com");
  129.   } catch (IOException ex) {
  130.   System.out.println(ex.getMessage());
  131.   }
  132.   }
  133.   }
  134.  
  135.   public void mouseEntered(MouseEvent e) {
  136.   timer.stop();
  137.   }
  138.  
  139.   public void mouseExited(MouseEvent e) {
  140.   timer.start();
  141.   }
  142.   });
  143.   add(googleLabel);
  144.   add(yahooLabel);
  145.   moveLabel();*/
  146. }
  147.  
  148. public void moveLabel() {
  149.  
  150. Rectangle r = new Rectangle();
  151. r.x = xLoc;
  152. r.y = yLoc;
  153. Dimension size;// = googleLabel.getPreferredSize();
  154. for(int i=0;i<stringlabel.length;i++)
  155. {
  156. JLabel label = new JLabel(stringlabel[i][0]);
  157. size = label.getPreferredSize();
  158. r.width = size.width;
  159. r.height = size.height;
  160. label.setBounds(r);
  161. r.x += r.width+5;
  162. }
  163. /*r.width = size.width;
  164.   r.height = size.height;
  165.   googleLabel.setBounds(r);
  166.  
  167.   // Append the Width of First Label to avoid overlapping
  168.   r.x += r.width + 5;
  169.   size = yahooLabel.getPreferredSize();
  170.   r.width = size.width;
  171.   r.height = size.height;
  172.   yahooLabel.setBounds(r);*/
  173.  
  174. xLoc -= 5;
  175. if (xLoc < 0 )
  176. xLoc = dimension.width;
  177. }
  178.  
  179.  
  180.  
  181. }
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Sandar Khin is offline Offline
18 posts
since Oct 2009
Nov 5th, 2009
0
Re: Error on repairing program
Are we supposed to read your mind? What do you need help doing?
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Nov 5th, 2009
0
Re: Error on repairing program
And don't you have about 5 threads started on this now?
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: What's the difference between a parent and predecessor node in binary search tree?
Next Thread in Java Forum Timeline: Question about tables





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC