- First, you must click on the hammer+broom button (Clean and Build project)
- The dist folder to be automatically generated after that.
- In the dist folder, you can see Jar (Executable jar File).
- Jar File is actually an executable file.
- *You can run this file through your Command Prompt program in your Windows.
*To run the project from the command line, go to the dist folder and type the following:
java -jar "xxx.jar"
If you are using Swing or AWT (fully GUI not the console), you can double-click on the Jar file to run your application!
Warning: If you choose GUI (Jar), you must add Swing Layout Extensions library to your Libraries trunk.
Enjoy!
Code : Tuto1.java (Main)
package tuto1;
import java.util.Scanner; //console input
import javax.swing.JOptionPane; //dialog (input or output)
public class Tuto1 {
public static void main(String[] args) {
/*
console input:-
Scanner user_input = new Scanner(System.in);
*/
String userName;
userName = JOptionPane.showInputDialog("Name?"); //dialog
/* Create two objects using constructor */
Employee empOne = new Employee(userName);
Employee empTwo = new Employee("Mary Anne");
// Invoking methods for each object created
empOne.empAge(26);
empOne.empDesignation("Senior Software Engineer");
empOne.empSalary(1000);
empOne.printEmployee();
empTwo.empAge(21);
empTwo.empDesignation("Software Engineer");
empTwo.empSalary(500);
empTwo.printEmployee();
}
}
Code : Employee.java
package tuto1;
public class Employee {
String name;
int age;
String designation;
double salary;
// This is the constructor of the class Employee
public Employee(String name){
this.name = name;
}
// Assign the age of the Employee to the variable age.
public void empAge(int empAge){
age = empAge;
}
/* Assign the designation to the variable designation.*/
public void empDesignation(String empDesig){
designation = empDesig;
}
/* Assign the salary to the variable salary.*/
public void empSalary(double empSalary){
salary = empSalary;
}
/* Print the Employee details */
public void printEmployee(){
System.out.println("Name:"+ name );
System.out.println("Age:" + age );
System.out.println("Designation:" + designation );
System.out.println("Salary:" + salary);
}
}
great
ReplyDelete