Analog Clock Application using Java. |
Tutorials, tips and tricks about java programming language. Answers for many doubts about java programming language. Answering many howtos. Sample java projects and source code, java games, java programs for java practical labs.
Search This Blog
Clock Application using Java - Java Source Code for Analog Clock Application
For my java practical lab experiments, i had to create an analog clock using java. So, i created a
simple analog clock using java. The program source code is added below. It makes use of java 2D Graphics Object and draws the clock in the screen. The clock displays all the three hands (hour hand, second hand and minute hand). The program source code is as follows. The screenshot of the java analog clock application is also added.
Simple Java Calculator Program Using Java Applet
Screenshot of Simple calculator applet in java |
How to Remove Title bar from JFrame of Java Application
To remove the title bar completely, there is a method called setUndecorated() in java. It takes a boolean variable. If the boolean is true, the title bar will be removed. The following one is an example. The method setUndecorated() invoked with a true boolean argument, will remove the title bar from the JFrame MyJFrame. The method is called here from the constructor. You may call it anywhere from within the class scope.
How to Close or Exit a Java App When some Button is Clicked
To close a Java app, System.exit() can be used. This function can be used to close the app if an error occurs or no error is occurred. If no, error occurred, the argument of the function should be 0. This method terminates the currently running Java Virtual Machine. The argument stands for status code; by convention, a nonzero status code indicates abnormal termination. If you are calling the System.exit() function without any errors (in normal case), just give the argument as zero. This method calls the exit method in class Runtime.
How to Use System.getProperty() - Keys for System Properties
There is a method getProperty() in System class in java. As the name indicates, this java method is used to get System specific, operating system specific or user specific properties. There are different keys which are strings passed as parameter to the getProperty() method.
Usage
The following sample java code will show you how to use the getProperty method in System class. The key is a string. The System.getProperty() method takes a string parameter (argument). Based on the string passed, the method System.getProperty() returns different properties as string. In this example,we pass "java.io.tmpdir" as the parameter, which is the key to get the temporary directory (temp directory) for the current user account.
String property = "java.io.tmpdir"; String tempDir = System.getProperty(property);
System.out.println("temp directory ="+ tempDir );
Similarly, for each property, there is a key. Below, the keys for different properties are listed.
- "file.separator"
- Gives the character that separates components of a file path. This is "/" on UNIX and "\" on Windows. This character is used in File paths for cross platform java applications
- "java.class.path"
- Returns the path used to find directories and JAR archives containing class files. Elements of the class path are separated by a platform-specific character specified in the path.separator property.
- "java.home"
- Returns the installation directory for Java Runtime Environment (JRE)
- "java.vendor"
- Returns the name of JRE vendor
- "java.vendor.url"
- Returns the URL of JRE vendor
- "java.version"
- Returns the version number of JRE
- "line.separator"
- Returns the character sequence used by operating system to separate lines in text files. This is operating system specific. It can be '\n', '\r' or "\r\n".
- "os.arch"
- Returns the operating system architecture
- "os.name"
- Returns the name of the Operating system
- "os.version"
- Returns the version of the Opposing system.
- "path.separator"
- Returns path separator character used in java.class.path
- "user.dir"
- Returns the path to the working directory of current user in the computer.
- "user.home"
- Returns the path to the home directory of current user.
- "user.name"
- Returns the name of current user (user account name)
Plane Shooter Game for PC -Java Game Project with Source code
Plane Shooter is a single player lightweight Java game for Computers. It is a 2D game that works well even on low end computers. The game size is only a few Kilobytes. You play as a tank and shoot down planes and what they drop. The game is in 7 or more levels. This is my first complete Greenfoot project. The source code of this game is also uploaded for those who want to see.
PanzerFight - Two player Action Game (Java Game) For Any OS
PanzerFight is an interesting two player game for PC. The game is played between two players on same computer (can be on same keyboard). Each player controls a tank. The tanks can plant land mines or fire each other. Ammunition and health are supplied at times. The game is interesting since it is a multi player game. This multiplayer shooting game is supported on, Windows, Linux, Solaris, Mac etc. The game is developed in Java platform (using Greenfoot). JRE (Java Run time Environment) is a prerequisite to run this game.
How to Change Image in JButton in Java - Set Icon of JButton
In this post we are discussing how to change the image in button in Java. There may be situations in
programming where we want to know how to set JButton image in java or to change button icon in java. The java code to change the icon of a Jbutton is so short. We use the
method in JButton class. The setIcon method takes an ImageIcon object as an argument. I will show you a sample java code in which the icon of button is set. First of all, you have to copy the icon image (jpg, bmp, png or gif image) to the src folder in the project directory. You may also place it in some folder inside the src folder. If you are using netbeans IDE, you can simply drag and drop the image file into the desired folder in the projects pane. After copying the icon image to src folder (or any subfolder in it), use the following code to set it as the button's icon.
Jbutton with Image set |
setIcon()
playbtn.setIcon(new ImageIcon(getClass().getResource("/manhaj/images/play.png"))); |
Online Mobile Recharge Simulation Application in Java
Here i am adding an online mobile recharge application. It is coded in Java. It is a java desktop application using pure java only and simulates online mobile recharge. It is done using Netbeans IDE. I am posting the link to the netbeans project file (zip archive). You can simply download it and extract it to see it using notepad or Netbeans IDE. This is a simple java SE desktop application using files to simulate online mobile recharge and online payment using debit card or credit card. Input validation, reading or writing objects from or to files, using arrays (ArrayList) of objects, displaying or showing multiple lines using JLabel, using HTML formating for JLabel text etc are features.
Download Netbeans Project (Java Source code) for Online Mobile Recharge Simulation application
How to Display Multiple Lines in JLabel
HTML formatted multiline JLabel |
JLabel lbl_Multiline=new JLabel(); lbl_Multiline.setText("<html>This is my long text to display with JLabel....</html>"); |
How to Change Shape of JFrame - Rounded Rectangle, Circle, Ellipse etc
You can change the shape of the JFrame. By default its shape is rectangular and assumes the size set using setSize() method. In this post we will discuss how to change the shape of JFrame. You can change JFrame's shape into rounded rectagle, cirlce, ellipse, etc. We will see how to set the shape of JFrame with java code sample and screenshots. To change the shape of JFrame to any shape, we use the setShape() method.
Prerequisites
There are some prerequisites for setting or changing the shape of JFrame. They are:
The Frame should be undecorated. You should call the setUndecorated(true) method before calling setShape() method. When you set the frame undecorated, you will lose the title-bar,close button, maximise and minimise buttons. So you will have to create these button syourself.
Subscribe to:
Posts (Atom)