Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java Applet Won't Load In Browser 2011 Java
#1
Code:
1. import java.awt.*; 2. import java.awt.event.*; 3. import javax.swing.*; 4. import java.applet.*; 5. public class FamilyTreeTabbedPane extends JApplet implements ActionListener, MouseListener{ 6. //Make buttons and labels local to the class so that they can be accessed by all methods, and the action performed method 7. JButton gButton, gTwoButton, gThreeButton,pButton, pTwoButton, pThreeButton,sButton, sTwoButton, sThreeButton,gPlay,gStop,pPlay,pStop,sPlay,sStop; 8. JLabel grandText, parentText, siblingText; 9. //create audio clips 10. AudioClip gac,pac,sac; 11. JTabbedPane tabPane; 12. public void init(){ 13. //initialize my jtabbedpane 14. tabPane = new JTabbedPane(); 15. //set up tabpane mouse listener to listen for when clicked event 16. tabPane.addMouseListener(this); 17. //set size of the applet 18. setSize(1400, 610); 19. //create a new tab with an icon and the appropriate returned panel 20. tabPane.addTab("Grandparent",new ImageIcon("grandIcon.jpg"), grandparentsTab()); 21. tabPane.addTab("Parents",new ImageIcon("parentIcon.jpg"),parentTab()); 22. tabPane.addTab("Siblings",new ImageIcon("siblingIcon.jpg"),siblingTab()); 23. //set the color of the tabbed panels 24. tabPane.setBackgroundAt(0, Color.CYAN); 25. tabPane.setBackgroundAt(1, Color.GREEN); 26. tabPane.setBackgroundAt(2, Color.magenta); 27. //add tabPane to the applet 28. add(tabPane); 29. } 30. //I normally would not have created three different method names, It adds alot of tedious work that can easily be circumvented by overloading the same one 31. //but in the instructions it said create three seperate methods for each tab, and I wasn't sure if method overloading was allowed, so I played it safe. 32. public JPanel grandparentsTab(){ 33. //create jpanel and Button 34. JPanel grand, borderFrame, audioPanel; 35. //setup audio clip 36. gac = getAudioClip( getCodeBase(),"make my dreams come true.wav"); 37. //create jButtons 38. gButton = new JButton(new ImageIcon("Grandparent.jpg")); 39. gTwoButton = new JButton(new ImageIcon("Grandparent2.jpg")); 40. gThreeButton = new JButton(new ImageIcon("Grandparent3.jpg")); 41. gPlay = new JButton("Play"); 42. gStop = new JButton("Stop"); 43. //create jLabel 44. grandText = new JLabel(" ",JLabel.CENTER); 45. //create jpanels 46. grand = new JPanel(); 47. audioPanel=new JPanel(); 48. borderFrame = new JPanel(new BorderLayout()); 49. //add action listeners 50. gButton.addActionListener(this); 51. gTwoButton.addActionListener(this); 52. gThreeButton.addActionListener(this); 53. gPlay.addActionListener(this); 54. gStop.addActionListener(this); 55. //add to panel 56. grand.add(gButton); 57. grand.add(gTwoButton); 58. grand.add(gThreeButton); 59. audioPanel.add(gPlay); 60. audioPanel.add(gStop); 61. //add items to borderFrame 62. borderFrame.add(grand,BorderLayout.CENTER); 63. borderFrame.add(grandText,BorderLayout.NORTH); 64. borderFrame.add(audioPanel,BorderLayout.SOUTH); 65. //return to panel 66. return borderFrame; 67. } 68. //refer to grandTab 69. public JPanel parentTab(){ 70. JPanel parent, borderFrame, audioPanel; 71. pac = getAudioClip( getCodeBase(),"sweet disposition.wav"); 72. pButton = new JButton(new ImageIcon("Parents.jpg")); 73. pTwoButton = new JButton(new ImageIcon("Parents2.jpg")); 74. pThreeButton = new JButton(new ImageIcon("Parents3.jpg")); 75. pPlay = new JButton("Play"); 76. pStop = new JButton("Stop"); 77. parentText = new JLabel(" ",JLabel.CENTER); 78. audioPanel=new JPanel(); 79. parent = new JPanel(); 80. borderFrame = new JPanel(new BorderLayout()); 81. pButton.addActionListener(this); 82. pTwoButton.addActionListener(this); 83. pThreeButton.addActionListener(this); 84. pPlay.addActionListener(this); 85. pStop.addActionListener(this); 86. parent.add(pButton); 87. parent.add(pTwoButton); 88. parent.add(pThreeButton); 89. audioPanel.add(pPlay); 90. audioPanel.add(pStop); 91. borderFrame.add(parent,BorderLayout.CENTER); 92. borderFrame.add(parentText,BorderLayout.NORTH); 93. borderFrame.add(audioPanel,BorderLayout.SOUTH); 94. return borderFrame; 95. } 96. //refer to grandTab 97. public JPanel siblingTab(){ 98. JPanel sibling, borderFrame, audioPanel; 99. sac = getAudioClip( getCodeBase(),"shes got you high.wav"); 100. sButton = new JButton(new ImageIcon("siblings.jpg")); 101. sTwoButton = new JButton(new ImageIcon("siblings2.jpg")); 102. sThreeButton = new JButton(new ImageIcon("siblings3.jpg")); 103. sPlay = new JButton("Play"); 104. sStop = new JButton("Stop"); 105. siblingText = new JLabel(" ",JLabel.CENTER); 106. audioPanel=new JPanel(); 107. sibling = new JPanel(); 108. borderFrame = new JPanel(new BorderLayout()); 109. sButton.addActionListener(this); 110. sTwoButton.addActionListener(this); 111. sThreeButton.addActionListener(this); 112. sPlay.addActionListener(this); 113. sStop.addActionListener(this); 114. sibling.add(sButton); 115. sibling.add(sTwoButton); 116. sibling.add(sThreeButton); 117. audioPanel.add(sPlay); 118. audioPanel.add(sStop); 119. borderFrame.add(sibling,BorderLayout.CENTER); 120. borderFrame.add(siblingText,BorderLayout.NORTH); 121. borderFrame.add(audioPanel,BorderLayout.SOUTH); 122. return borderFrame; 123. } 124. public void actionPerformed(ActionEvent event) { 125. Object src = event.getSource(); 126. 127. if(src == gButton) 128. grandText.setText("This is my grandma!"); 129. else if(src == gTwoButton) 130. grandText.setText("This is my grandma and my Family!"); 131. else if(src == gThreeButton) 132. grandText.setText("This is my grandma and my mother!"); 133. else if(src == pButton) 134. parentText.setText("My mom, dad, and my nephew!"); 135. else if(src == pTwoButton) 136. parentText.setText("My mom and dad dancing!"); 137. else if(src == pThreeButton) 138. parentText.setText("My mom and dad 80's style!"); 139. else if(src == sButton) 140. siblingText.setText("Me my brother and my sister!"); 141. else if(src == sTwoButton) 142. siblingText.setText("Wow was I young here!"); 143. else if(src == sThreeButton) 144. siblingText.setText("Me and my sister!"); 145. else if(src == gPlay){ 146. stopMusic(sac); 147. stopMusic(pac); 148. gac.play(); 149. }else if(src == gStop) 150. stopMusic(gac); 151. else if(src == pPlay){ 152. stopMusic(gac); 153. stopMusic(sac); 154. pac.play(); 155. }else if(src == pStop) 156. stopMusic(pac); 157. else if(src == sPlay){ 158. stopMusic(gac); 159. stopMusic(pac); 160. sac.play(); 161. }else if(src == sStop) 162. stopMusic(sac); 163. 164. } 165. private void stopMusic(AudioClip clip){ 166. //check if clip is playing if it is stop it 167. if(clip != null) 168. clip.stop(); 169. } 170. public void mouseClicked(MouseEvent me) 171. { 172. 173. int tabindex = tabPane.getSelectedIndex(); 174. 175. if (tabindex == 0) 176. { 177. gac.play(); 178. pac.stop(); 179. sac.stop(); 180. } 181. else if (tabindex == 1) 182. { 183. pac.play(); 184. gac.stop(); 185. sac.stop(); 186. } 187. else if (tabindex == 2) 188. { 189. sac.play(); 190. gac.stop(); 191. pac.stop(); 192. } 193. } 194. 195. public void mouseEntered(MouseEvent me){} 196. public void mouseExited(MouseEvent me){} 197. public void mousePressed(MouseEvent me){} 198. public void mouseReleased(MouseEvent me){} 199. 200. }

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to run a java file that creaded in Ntebeans in console Vuhelper 1 4,976 08-01-2012, 10:23 PM
Last Post: Pari ch
  Send image to client over a socket in java 2011 Vuhelper 1 3,678 04-21-2012, 02:11 AM
Last Post: hoailenpro
  double buffering in java 2011-12 Vuhelper 0 2,203 09-12-2011, 10:30 PM
Last Post: Vuhelper
  Using wait and notify? in java 2011-12 Vuhelper 0 2,131 09-12-2011, 10:29 PM
Last Post: Vuhelper
  text wrap in java 2011-12 Vuhelper 0 2,142 09-12-2011, 10:27 PM
Last Post: Vuhelper
  How find the data in ArrayList? 2011-12 Vuhelper 0 2,497 09-04-2011, 07:21 AM
Last Post: Vuhelper
  TableModelListener ERROR in Java 2011 Vuhelper 0 2,034 07-23-2011, 05:47 PM
Last Post: Vuhelper
  Exception Handling in Java 2011 Vuhelper 0 1,986 07-23-2011, 05:46 PM
Last Post: Vuhelper
  Getting the element of a vector in Java 2011 Vuhelper 0 1,888 07-23-2011, 05:45 PM
Last Post: Vuhelper
  program does not enter for loop in Java 2011 Vuhelper 0 2,088 07-23-2011, 05:44 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)