Error on repairing program

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

Join Date: Oct 2009
Posts: 14
Reputation: Sandar Khin is an unknown quantity at this point 
Solved Threads: 1
Sandar Khin Sandar Khin is offline Offline
Newbie Poster

Error on repairing program

 
0
  #1
29 Days Ago
Hi all.
pls help me.I repair a program for my need.At that time Text are not appear.Original progarm is here.
  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
  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. }
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,597
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso
 
0
  #2
29 Days Ago
Are we supposed to read your mind? What do you need help doing?
Out.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is online now Online
Industrious Poster
 
0
  #3
29 Days Ago
And don't you have about 5 threads started on this now?
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC