Click here to Skip to main content
11,412,111 members (67,169 online)
   

Java

 
AnswerRe: Java code Convert to C# PinmemberBernhard Hiller13-Nov-12 22:14 
GeneralRe: Java code Convert to C# PinmemberLAPEC14-Nov-12 1:19 
QuestionRe: Java code Convert to C# PinmemberBlikkies14-Nov-12 2:06 
GeneralRe: Java code Convert to C# PinmvpRichard MacCutchan14-Nov-12 2:34 
AnswerRe: Java code Convert to C# PinmvpRichard MacCutchan13-Nov-12 22:16 
AnswerRe: Java code Convert to C# PinmemberDave Doknjas17-Nov-12 4:17 
QuestionTower of hanoi in java Pinmemberprog.sidra11-Nov-12 22:19 
AnswerRe: Tower of hanoi in java PinmvpRichard MacCutchan11-Nov-12 22:49 
AnswerRe: Tower of hanoi in java PinmemberTorstenH.12-Nov-12 1:22 
GeneralRe: Tower of hanoi in java Pinmemberprog.sidra12-Nov-12 20:58 
QuestionIf element in diagonal is 1 then its unit matrix , else it's not unit matrix [modified] PinmemberAsad JOgi11-Nov-12 20:26 
AnswerRe: If element in diagonal is 1 then its unit matrix , else it's not unit matrix PinmemberTorstenH.11-Nov-12 22:15 
AnswerRe: If element in diagonal is 1 then its unit matrix , else it's not unit matrix PinmemberBobJanova13-Nov-12 1:06 
QuestionError show ImageIcon ??? Pinmembernghia09t39-Nov-12 20:34 
I want to show ImageIcon by adding to Label, but it has error, help me?
<pre lang="java">import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
import java.util.Scanner;
class CatchTheRat extends JFrame
{
// The Rat
JLabel lb;

// Move it randomly!
Random r;

public CatchTheRat(int k)
{

// Set frame properties
setTitle("Catch The Rat");
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);

// Set the background (just for a good look)
setContentPane(new JLabel(new ImageIcon("background.jpg")));

// Set layout to the content pane
getContentPane().setLayout(new FlowLayout());

// Create the rat
lb=new JLabel(new ImageIcon("rat.jpg"));

// Add the rat
getContentPane().add(lb);

// Create Random object
r=new Random();

// Create a timer and call it for every k seconds
new Timer(k,new ActionListener(){

   public void actionPerformed(ActionEvent ae)
   {
  
   // Move the rat randomly, subtract 75, so that the rat should not meet the edges
   lb.setLocation(r.nextInt(getWidth()-75),r.nextInt(getHeight()-75));

   }

}).start();

// Add mouselistener, notify when user clicks it!
lb.addMouseListener(new MouseAdapter(){

   public void mouseClicked(MouseEvent me)
   {
   // Create a beep sound when clicked to notify
   Toolkit.getDefaultToolkit().beep();

   // Also print it!
   System.out.println("Caught!");
   }

});

// Maximize the frame
setExtendedState(MAXIMIZED_BOTH);

}

public static void main(String args[])
{

// Create Scanner object
Scanner s=new Scanner(System.in);

// Let the user enter his capability of catching the rat!
System.out.println("Enter the speed");

// Read the input
int k=s.nextInt();

// Create the frame and send the value of k
new CatchTheRat(k);

}
}
</pre>
AnswerRe: Error show ImageIcon ??? PinmvpRichard MacCutchan10-Nov-12 0:32 
AnswerRe: Error show ImageIcon ??? PinmemberTorstenH.10-Nov-12 15:02 
GeneralRe: Error show ImageIcon ??? PinmemberGowtham Gutha15-Nov-12 7:46 
GeneralRe: Error show ImageIcon ??? PinmemberTorstenH.15-Nov-12 10:00 
GeneralRe: Error show ImageIcon ??? PinmemberGowtham Gutha16-Nov-12 8:08 
GeneralRe: Error show ImageIcon ??? PinmemberTorstenH.18-Nov-12 20:10 
AnswerRe: Error show ImageIcon ??? PinmemberGowtham Gutha15-Nov-12 7:43 
Questionhow to create digital survey android and php?? PinmemberLuis Antonio Mantilla9-Nov-12 13:22 
QuestionAny Java Book Recommend Pinmemberwaylife7-Nov-12 20:14 
AnswerRe: Any Java Book Recommend PinmemberPeter_in_27808-Nov-12 2:13 
GeneralRe: Any Java Book Recommend Pinmemberwaylife12-Nov-12 23:07 
AnswerRe: Any Java Book Recommend PinmemberGowtham Gutha9-Nov-12 10:02 
GeneralRe: Any Java Book Recommend Pinmemberwaylife12-Nov-12 23:08 
GeneralRe: Any Java Book Recommend PinmemberGowtham Gutha15-Nov-12 1:22 
GeneralRe: Any Java Book Recommend Pinmemberwaylife15-Nov-12 4:10 
GeneralRe: Any Java Book Recommend Pinmemberwaylife14-Nov-12 1:54 
AnswerRe: Any Java Book Recommend PinmemberIvan Melnikov1-Jul-13 23:38 
QuestionHow to create/set an element of a document Pinmemberprithaa6-Nov-12 4:43 
AnswerRe: How to create/set an element of a document Pinmemberpadmanabanproject7-Nov-12 20:58 
GeneralRe: How to create/set an element of a document Pinmemberprithaa4-Dec-12 4:55 
Questionhow to Use Java to get the database info by Internet Protocol [modified] PinmemberXMafei5-Nov-12 5:03 
AnswerRe: how to Use Java to get the database info by Internet Protocol PinmvpRichard MacCutchan5-Nov-12 6:24 
GeneralRe: how to Use Java to get the database info by Internet Protocol PinmemberXMafei5-Nov-12 14:58 
GeneralRe: how to Use Java to get the database info by Internet Protocol PinmvpRichard MacCutchan5-Nov-12 23:13 
AnswerRe: how to Use Java to get the database info by Internet Protocol Pinmemberjschell5-Nov-12 9:33 
Questionaddress book in java PinmemberShah Baba5-Nov-12 4:19 
AnswerRe: address book in java PinmvpRichard MacCutchan5-Nov-12 4:24 
Questionhi PinmemberMd Abdullah Al Masud4-Nov-12 20:00 
Questionjava progarm Pinmemberhardikv923-Nov-12 23:45 
AnswerRe: java progarm PinmvpRichard MacCutchan4-Nov-12 3:05 
AnswerRe: java progarm PinmemberGowtham Gutha15-Nov-12 2:15 
AnswerRe: java progarm PinmemberMember 1111060025-Sep-14 17:52 
QuestionUpdating content of JtextField through jbutton in sql server 2005 using netbeans ide and jdk 1.6 PinmemberMember 95656712-Nov-12 1:14 
AnswerRe: Updating content of JtextField through jbutton in sql server 2005 using netbeans ide and jdk 1.6 PinmvpRichard MacCutchan2-Nov-12 1:47 
Question[JAVA] web log file Pinmembermariankral1-Nov-12 2:53 
AnswerRe: [JAVA] web log file PinmemberTorstenH.1-Nov-12 5:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 26 Apr 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid