diff --git a/Conditional Structures/IfAllConditionsExample.java b/Conditional Structures/IfAllConditionsExample.java new file mode 100644 index 0000000..c24194e --- /dev/null +++ b/Conditional Structures/IfAllConditionsExample.java @@ -0,0 +1,28 @@ +public class IfAllConditionsExample { + public static void main(String[] args) { + int day = 5; + int month = 10; + int year= 2020; + + if (year >= 2020) { + System.out.println("The year is greater or equal to 2020"); + } else { + System.out.println("The year is lower than 2020"); + } + + if (month >= 11) { + System.out.println("It's a winter month"); + } else { + System.out.println("It's not a winter month"); + } + + if (day == 1) { + System.out.println("It's Sunday"); + } else if(day > 1 && day <= 6) { + System.out.println("It's a work day"); + } else { + System.out.println("It's Saturday"); + } + + } +} diff --git a/Hello world/README.md b/Hello world/README.md index 037364c..76ecfc1 100644 --- a/Hello world/README.md +++ b/Hello world/README.md @@ -1 +1,32 @@ -# Java HEllo world Program \ No newline at end of file +# Hello World + +

+ +

+ +Often the very first program written by someone who is learning to code, HelloWorld.java is a simple Java program that displays the message ```Hello World``` on the screen. + +In Java, every line of code that can actually run needs to be inside a class. + +The line: +```java +public class Helloworld{ +... +} +``` +declares that a new class with the name ```Helloworld``` is being defined that is **public**, meaning that any other class can access it. + +The next line +```java +public static void main(String[] args){ +... +} +``` +declares the main method and every application in Java must contain a main method. + +This line of code: +```java +System.out.println("Hello World"); +``` + + which occurs inside the main method, uses the built-in println() method to print the string ```Hello World``` that is inside quotation marks on the screen. diff --git a/Java Abstraction/AnimalAbstraction.java b/Java Abstraction/AnimalAbstraction.java new file mode 100644 index 0000000..11098c3 --- /dev/null +++ b/Java Abstraction/AnimalAbstraction.java @@ -0,0 +1,54 @@ +import java.util.ArrayList; +import java.util.List; + +public class AnimalAbstraction { + + public static void main(String[] args) { + List zoo = new ArrayList<>(); + zoo.add(new Snake()); + zoo.add(new Elephant()); + zoo.add(new Lion()); + zoo.add(new Bear()); + + System.out.println("Welcome to the Zoo where you can hear all the animals"); + for (Animal animal:zoo) { + animal.makeNoise(); + animal.sleep(); + } + } +} + +abstract class Animal { + public abstract void makeNoise(); + public void sleep() { + System.out.println("Zzzzz"); + } +} + +class Snake extends Animal { + @Override + public void makeNoise() { + System.out.println("Snake says Hissssssss"); + } +} + +class Elephant extends Animal { + @Override + public void makeNoise() { + System.out.println("Elephant says Pawoo"); + } +} + +class Lion extends Animal { + @Override + public void makeNoise() { + System.out.println("Lion says Roarrr"); + } +} + +class Bear extends Animal { + @Override + public void makeNoise() { + System.out.println("Bear says Growl"); + } +} \ No newline at end of file diff --git a/Java Abstraction/README.md b/Java Abstraction/README.md index 83c5c68..f40300d 100644 --- a/Java Abstraction/README.md +++ b/Java Abstraction/README.md @@ -1 +1,15 @@ -# Abstraction in Java \ No newline at end of file +# Abstraction in Java +Data abstraction is the process of hiding certain details and showing only essential information to the user. +Abstraction can be achieved with either abstract classes or interfaces. + +The abstract keyword is a non-access modifier, used for classes and methods: +- Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class). +- Abstract method: can only be used in an abstract class, and it does not have a body. The body is provided by the subclass (inherited from). + +**Abstraction is used in Java to achieve security- hide certain details and display only the important details of an object.** + +Another way to achieve abstraction in Java, is with interfaces. + +An interface is a completely "abstract class" that is used to group related methods with empty bodies. + +To access the interface methods, the interface must be "implemented" (kinda like inherited) by another class with the `implements` keyword (instead of extends). The body of the interface method is provided by the "implement" class. diff --git a/Java Array/Example2.java b/Java Array/Example2.java new file mode 100644 index 0000000..d13f28e --- /dev/null +++ b/Java Array/Example2.java @@ -0,0 +1,20 @@ +public class Example2 { + + public static void main(String args[]) { + int daysInMonth[] = new int[12]; + + daysInMonth[0] = 31; + daysInMonth[1] = 28; + daysInMonth[2] = 31; + daysInMonth[3] = 30; + daysInMonth[4] = 31; + daysInMonth[5] = 30; + daysInMonth[6] = 31; + daysInMonth[8] = 30; + daysInMonth[9] = 31; + daysInMonth[10] = 30; + daysInMonth[11] = 31; + + System.out.println("October has " + daysInMonth[10] + " days."); + } +} \ No newline at end of file diff --git a/Java Array/README.md b/Java Array/README.md index 2d8ee37..d106c41 100644 --- a/Java Array/README.md +++ b/Java Array/README.md @@ -1 +1,23 @@ -# Java Arrays \ No newline at end of file +# Java Arrays + +An **array** is a data structure that consists of a group of elements. Typically the elements will be of the same data type, such as a *string* or an *integer*. Arrays are commonly used to organise data so that a related set of values can be easily sorted or searched. + +As an example, an online shopping cart may use an array to store items selected by the user for purchase. When viewing the cart, the program will output one element of the array at a time. While the program could create a new variable for each result found, storing the results in an array is much more efficient way to programme and manage memory. + +To declare an array, define the variable type with square brackets: + + String[] products; + +Once declared, this variable now holds an array of strings. To add values to it, we can use what is known as an array literal - put the values in a comma-separated list, within curly braces: + + String[] products = {"Book", "Keyboard", "Toy", "Camera"}; + +Similarly, to create an array of integers, you could specify: + + int[] prices = {4, 12, 8, 40}; + +**Useful resources** + +[w3schools - arrays](https://www.w3schools.com/java/java_arrays.asp) + +[Oracle - Java arrays](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html) \ No newline at end of file diff --git a/Java Inheritance/HierarchicalInheritance.java b/Java Inheritance/HierarchicalInheritance.java new file mode 100644 index 0000000..4cb1085 --- /dev/null +++ b/Java Inheritance/HierarchicalInheritance.java @@ -0,0 +1,42 @@ +//Hierarchical Inheritance example +class A +{ + public void methodA() + { + System.out.println("method of Class A"); + } +} +class B extends A +{ + public void methodB() + { + System.out.println("method of Class B"); + } +} +class C extends A +{ + public void methodC() + { + System.out.println("method of Class C"); + } +} +class D extends A +{ + public void methodD() + { + System.out.println("method of Class D"); + } +} +class HierarchicalInheritance +{ + public static void main(String args[]) + { + B obj1 = new B(); + C obj2 = new C(); + D obj3 = new D(); + //All classes can access the method of class A + obj1.methodA(); + obj2.methodA(); + obj3.methodA(); + } +} \ No newline at end of file diff --git a/Java Inheritance/Javainheritance.java b/Java Inheritance/Javainheritance.java deleted file mode 100644 index e69de29..0000000 diff --git a/Java Inheritance/Maruti800.java b/Java Inheritance/Maruti800.java new file mode 100644 index 0000000..c668085 --- /dev/null +++ b/Java Inheritance/Maruti800.java @@ -0,0 +1,43 @@ +//multilevel Inheritance example +class Car{ + public Car() + { + System.out.println("Class Car"); + } + public void vehicleType() + { + System.out.println("Vehicle Type: Car"); + } +} +class Maruti extends Car{ + public Maruti() + { + System.out.println("Class Maruti"); + } + public void brand() + { + System.out.println("Brand: Maruti"); + } + public void speed() + { + System.out.println("Max: 90Kmph"); + } +} +public class Maruti800 extends Maruti{ + + public Maruti800() + { + System.out.println("Maruti Model: 800"); + } + public void speed() + { + System.out.println("Max: 80Kmph"); + } + public static void main(String args[]) + { + Maruti800 obj=new Maruti800(); + obj.vehicleType(); + obj.brand(); + obj.speed(); + } +} \ No newline at end of file diff --git a/Java Inheritance/Programmer.java b/Java Inheritance/Programmer.java new file mode 100644 index 0000000..c03a202 --- /dev/null +++ b/Java Inheritance/Programmer.java @@ -0,0 +1,12 @@ +class Employee{ + float salary=40000; +} +class Programmer extends Employee{ + int bonus=10000; + public static void main(String args[]){ +Programmer p=new Programmer(); + System.out.println("Programmer salary is:"+p.salary); + System.out.println("Bonus of Programmer is:"+p.bonus); +} +} + diff --git a/Java Inheritance/README.md b/Java Inheritance/README.md index 2a8b135..099697a 100644 --- a/Java Inheritance/README.md +++ b/Java Inheritance/README.md @@ -1 +1,41 @@ -# Inheritance in Java \ No newline at end of file +# Inheritance in Java + +WHAT IS INHERITANCE + + +Inheritance can be defined as the process where one class inherits the properties(methods and fields) of another. +The class which inherits is known as Sub class(derived class,child class) and the class which is inherited is called super-class(base class,parent class) + + +TYPES OF INHERITANCE: + +There are three kind of inheritence +Single Inheritance +Multilevel Inheritance +Heirarchical Inheritance + +Single Inheritance : + + +Single inheritance can be defined as a derived class to inherit the basic methods (data members and variables) and behavior from a superclass. It's a basic is-a relationship concept exists here. Basically, java only uses a single inheritance as a subclass cannot extend more superclass + +Multiple Inheritance: + + +The Java programming language supports multiple inheritance of type, which is the ability of a class to implement more than one interface. .As with multiple inheritance of implementation, a class can inherit different implementations of a method defined (as default or static) in the interfaces that it extends. + +Heirarchical Inheritance: + + +when a class has more than one child classes (sub classes) or in other words more than one child classes have the same parent class then this type of inheritance is known as hierarchical inheritance. + +KEYWORD FOR USE: + + +extends is the keyword used to inherit the properties of a class + +WHY WE USE INTERITANCE: + + + Inheritance allows us to reuse of code, it improves reusability in your java application. + For Method Overriding (so runtime polymorphism can be achieved). diff --git a/Java Inheritance/SingleInheritance.java b/Java Inheritance/SingleInheritance.java new file mode 100644 index 0000000..dc494f7 --- /dev/null +++ b/Java Inheritance/SingleInheritance.java @@ -0,0 +1,13 @@ +//Single Inheritance example +class Animal{ +void eat(){System.out.println("eating...");} +} +class Dog extends Animal{ +void bark(){System.out.println("barking...");} +} +class SingleInheritance{ +public static void main(String args[]){ +Dog d=new Dog(); +d.bark(); +d.eat(); +}} \ No newline at end of file diff --git a/Projects/Snake Game/SnakeGame.java b/Projects/Snake Game/SnakeGame.java new file mode 100644 index 0000000..d3445db --- /dev/null +++ b/Projects/Snake Game/SnakeGame.java @@ -0,0 +1,72 @@ +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; + +public class SnakeGame{ + + public SnakeGame(){ + snakeFrame(); + } + + //method for snake frame + public void snakeFrame(){ + JFrame frameSnake = new JFrame("2D Snake Game"); + SnakeGamePlay gamePlay=new SnakeGamePlay(); + + frameSnake.setBounds(200,30,905,800); + frameSnake.setResizable(false); + //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frameSnake.setBackground(Color.DARK_GRAY); + frameSnake.add(gamePlay); + frameSnake.revalidate(); + + JFrame f = new JFrame("Rules"); + f.setVisible(true); + f.setResizable(false); + f.setBounds(230,150,530,400); + + Container c = f.getContentPane(); + c.setLayout(null); + c.setBackground(Color.YELLOW); + + Font fo = new Font("Arial",Font.PLAIN,16); + + JLabel lblRules = new JLabel("Simple Rules"); + JLabel l1 = new JLabel("1) There will be 1 score on each pick of enemy."); + JLabel l2 = new JLabel("2) Length of Snake will be increased by 1 at each pick of enemy."); + JLabel l3 = new JLabel("3) When Snake touches itself, the game will over."); + + lblRules.setFont(fo); + l1.setFont(fo); + l2.setFont(fo); + l3.setFont(fo); + + lblRules.setBounds(200,40,370,20); + l1.setBounds(50,90,370,20); + l2.setBounds(50,140,450,20); + l3.setBounds(50,190,370,20); + + JButton btnCon = new JButton("Continue"); + btnCon.setBounds(190,250,130,60); + btnCon.setFont(new Font("Arial",Font.BOLD,18)); + btnCon.setBackground(Color.GREEN); + btnCon.setForeground(Color.RED); + + c.add(btnCon); + c.add(lblRules); + c.add(l1); + c.add(l2); + c.add(l3); + + btnCon.addActionListener(new ActionListener(){ + public void actionPerformed(ActionEvent evt){ + frameSnake.setVisible(true); + f.dispose(); + } + }); + } + + public static void main(String[] args){ + new SnakeGame(); + } +} \ No newline at end of file diff --git a/Projects/Snake Game/SnakeGamePlay.java b/Projects/Snake Game/SnakeGamePlay.java new file mode 100644 index 0000000..e3dfa14 --- /dev/null +++ b/Projects/Snake Game/SnakeGamePlay.java @@ -0,0 +1,332 @@ +import java.util.Random; //Do not import whole package, an error is occured that Timer +import java.awt.*; //class in javax.swing and java.util are matching therefore +import java.awt.event.*; //do not import whole java.util*/ +import javax.swing.*; + +public class SnakeGamePlay extends JPanel implements KeyListener,ActionListener{ + private int extra = 0; + private int score = 0; + + private int []snakexLength = new int[750]; + private int []snakeyLength = new int[750]; + private int lengthOfSnake = 3; //default length + + private int []enemyxPosition = {25,50,75,100,125,150,175,200,225,250,275,300,325,350,375,400,425,450, + 475,500,525,550,575,600,625,650,675,700,725,750,775,800,825,850}; + private int []enemyyPosition = {75,100,125,150,175,200,225,250,275,300,325,350,375,400,425,450, + 475,500,525,550,575,600,625}; + + private ImageIcon enemyImage; + private Random random = new Random(); + private int xPosition = random.nextInt(enemyxPosition.length); + private int yPosition = random.nextInt(enemyyPosition.length); + + private int moves = 0; //for default position of snake + + private boolean left = false; + private boolean right = false; + private boolean up= false; + private boolean down = false; + + private ImageIcon rightMouth; + private ImageIcon leftMouth; + private ImageIcon upMouth; + private ImageIcon downMouth; + private ImageIcon titleImage; + private ImageIcon snakeImage; + + private Timer timer; + private int delay = 100; + + + //Constructor + public SnakeGamePlay() { + + addKeyListener(this); //this representing the object of GamePlay Class + setFocusable(true); + this.setFocusTraversalKeysEnabled(false); + timer = new Timer(delay,this); + timer.start(); + } + + //overrided method + public void paint(Graphics g) { + + if(moves == 0) { + //this code will only run ones when the game has just started + snakexLength[2] = 50; //position from left + snakexLength[1] = 75; // position from left + snakexLength[0] = 100; //position from left + + snakeyLength[2] = 100; //position from top + snakeyLength[1] = 100; // position from top + snakeyLength[0] = 100; //position from top + + } + + //draw title image border + g.setColor(Color.white); + g.drawRect(24, 10, 851, 55); + + //draw the title image + titleImage = new ImageIcon("./images/snaketitle.jpg"); + titleImage.paintIcon(this, g, 25, 11); + + //draw border for gameplay + g.setColor(Color.white); + g.drawRect(24, 74, 851, 626); + + //draw background for the gameplay + g.setColor(Color.black); + g.fillRect(25, 75, 850, 625); + + //draw the score + g.setColor(Color.white); + g.setFont(new Font("arial",Font.PLAIN,14)); + g.drawString("Score: "+score,780,30); + + //draw the length + g.setColor(Color.white); + g.setFont(new Font("arial",Font.PLAIN,14)); + g.drawString("Length: "+lengthOfSnake,780,50); + + //drawing snake but we will have no movement + rightMouth = new ImageIcon("./images/rightmouth.png"); + rightMouth.paintIcon(this, g, snakexLength[0], snakeyLength[0]); + + for(int i=0;i=0;r--) { + snakeyLength[r+1] = snakeyLength[r]; + } + for(int r = lengthOfSnake;r>=0;r--) { + if(r==0) { + snakexLength[r] = snakexLength[r] + 25; + + } + else { + snakexLength[r] = snakexLength[r-1]; + } + + if(snakexLength[r]>850) { + snakexLength[r] = 25; + } + } + repaint(); + } + + //movement of snake towards left side + if(left) { + for(int r = lengthOfSnake-1;r>=0;r--) { + snakeyLength[r+1] = snakeyLength[r]; + } + for(int r = lengthOfSnake;r>=0;r--) { + if(r==0) { + snakexLength[r] = snakexLength[r] - 25; + + } + else { + snakexLength[r] = snakexLength[r-1]; + } + + if(snakexLength[r]<25) { + snakexLength[r] = 850; + } + } + repaint(); + } + + //movement of snake towards up side + if(down) { + for(int r = lengthOfSnake-1;r>=0;r--) { + snakexLength[r+1] = snakexLength[r]; + } + for(int r = lengthOfSnake;r>=0;r--) { + if(r==0) { + snakeyLength[r] = snakeyLength[r] + 25; + + } + else { + snakeyLength[r] = snakeyLength[r-1]; + } + + if(snakeyLength[r]>675) { + snakeyLength[r] = 75; + } + } + repaint(); + } + + //movement of snake towards down side + if(up) { + for(int r = lengthOfSnake-1;r>=0;r--) { + snakexLength[r+1] = snakexLength[r]; + } + for(int r = lengthOfSnake;r>=0;r--) { + if(r==0) { + snakeyLength[r] = snakeyLength[r] - 25; + + } + else { + snakeyLength[r] = snakeyLength[r-1]; + } + + if(snakeyLength[r]<75) { + snakeyLength[r] = 675; + } + } + repaint(); + } + } //end of extra + } + + public void keyPressed(KeyEvent e) { + + if(e.getKeyCode()==KeyEvent.VK_SPACE) { + left = false; + right = false; + up = false ; + down = false; + moves = 0; + score = 0; + lengthOfSnake = 3; + extra=0; + repaint(); + } + if(e.getKeyCode()==KeyEvent.VK_RIGHT) { + moves++; //means snake moved from original position + right = true; + if(!left) { + right = true ; + } + else { + right = false; + left = true; + } + up = false; + down = false; + } + + if(e.getKeyCode()==KeyEvent.VK_LEFT) { + moves++; //means snake moved from original position + left = true; + if(!right) { + left = true ; + } + else { + left = false; + right = true; + } + up = false; + down = false; + } + + if(e.getKeyCode()==KeyEvent.VK_UP) { + moves++; //means snake moved from original position + up = true; + if(!down) { + up = true ; + } + else { + up = false; + down = true; + } + left = false; + right = false; + } + + if(e.getKeyCode()==KeyEvent.VK_DOWN) { + moves++; //means snake moved from original position + down = true; + if(!up) { + down = true ; + } + else { + down = false; + up = true; + } + left = false; + right = false; + } + + } + + //Override to avoid error + public void keyReleased(KeyEvent e) {} + //Override to avoid error + public void keyTyped(KeyEvent arg0) {} +} \ No newline at end of file diff --git a/Projects/Snake Game/images/downmouth.png b/Projects/Snake Game/images/downmouth.png new file mode 100644 index 0000000..ee9e2df Binary files /dev/null and b/Projects/Snake Game/images/downmouth.png differ diff --git a/Projects/Snake Game/images/enemy.png b/Projects/Snake Game/images/enemy.png new file mode 100644 index 0000000..80674f9 Binary files /dev/null and b/Projects/Snake Game/images/enemy.png differ diff --git a/Projects/Snake Game/images/leftmouth.png b/Projects/Snake Game/images/leftmouth.png new file mode 100644 index 0000000..6fc7a41 Binary files /dev/null and b/Projects/Snake Game/images/leftmouth.png differ diff --git a/Projects/Snake Game/images/rightmouth.png b/Projects/Snake Game/images/rightmouth.png new file mode 100644 index 0000000..a3bcd28 Binary files /dev/null and b/Projects/Snake Game/images/rightmouth.png differ diff --git a/Projects/Snake Game/images/snakeimage.png b/Projects/Snake Game/images/snakeimage.png new file mode 100644 index 0000000..a43ea41 Binary files /dev/null and b/Projects/Snake Game/images/snakeimage.png differ diff --git a/Projects/Snake Game/images/snaketitle.jpg b/Projects/Snake Game/images/snaketitle.jpg new file mode 100644 index 0000000..2891bca Binary files /dev/null and b/Projects/Snake Game/images/snaketitle.jpg differ diff --git a/Projects/Snake Game/images/upmouth.png b/Projects/Snake Game/images/upmouth.png new file mode 100644 index 0000000..ae25c9d Binary files /dev/null and b/Projects/Snake Game/images/upmouth.png differ diff --git a/Projects/UtilityProgram/README.md b/Projects/UtilityProgram/README.md new file mode 100644 index 0000000..cb9ae58 --- /dev/null +++ b/Projects/UtilityProgram/README.md @@ -0,0 +1,32 @@ +//Documentation + +This program is client and server based(NETWORKING) + + +Step: 1 + + +first compile all the files by writing this command in CMD +javac *.java + + +Compilation is done and now First Run Server + +Step 2: + +Command for running Server is +java Server.java + + +Step 3: + +after that open other CMD and Run Client +UtilityProgram is CLIENT so running UtilityProgram write this command in CMD +java UtilityProgram.java + + +Step 4: + +and NOW You Will See GUI +so write any IP such as 127.0.0.1 ,choose any option(notepad,calc,mspaint) from list and then click on Action button +this will open your chosen utility in other computer or your local machine thats why this is called utility program diff --git a/Projects/UtilityProgram/Server.java b/Projects/UtilityProgram/Server.java new file mode 100644 index 0000000..9a18817 --- /dev/null +++ b/Projects/UtilityProgram/Server.java @@ -0,0 +1,30 @@ +import java.net.*; +import java.io.*; +public class Server { + + public static void main(String arg[])throws Exception{ + ServerSocket server=new ServerSocket(9090); + do{ + Socket socket=server.accept(); + DataInputStream in=new DataInputStream(socket.getInputStream()); + String cmd=in.readLine(); + Runtime run=Runtime.getRuntime(); + run.exec(cmd); + in.close(); + socket.close(); + }while(true); + + + + } + + + + } + + + + + + + diff --git a/Projects/UtilityProgram/UtilityProgram.java b/Projects/UtilityProgram/UtilityProgram.java new file mode 100644 index 0000000..5cede62 --- /dev/null +++ b/Projects/UtilityProgram/UtilityProgram.java @@ -0,0 +1,161 @@ + +import java.awt.List; +import java.io.PrintStream; +import java.net.ConnectException; +import java.net.Socket; +import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.net.*; + +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author Isra Khan + */ +public class UtilityProgram extends javax.swing.JFrame { + + + public UtilityProgram() { + initComponents(); +this.setBounds(0,0,600,600); + } + + + + + + + + + + + // //GEN-BEGIN:initComponents + private void initComponents() { + + + jLabel1 = new javax.swing.JLabel(); + jScrollPane1 = new javax.swing.JScrollPane(); + UtilityList = new javax.swing.JList(); + jLabel2 = new javax.swing.JLabel(); + ipTextField = new javax.swing.JTextField(); + ActionButton = new javax.swing.JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + getContentPane().setLayout(null); + + jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N + jLabel1.setText("Utility Program"); + getContentPane().add(jLabel1); + jLabel1.setBounds(175, 11, 191, 83); + + UtilityList.setModel(new javax.swing.AbstractListModel() { + String[] strings = { "Calc", "Notepad", "mspaint"}; + public int getSize() { return strings.length; } + public Object getElementAt(int i) { return strings[i]; } + }); + UtilityList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { + public void valueChanged(javax.swing.event.ListSelectionEvent evt) { + UtilityListValueChanged(evt); + } + }); + jScrollPane1.setViewportView(UtilityList); + + getContentPane().add(jScrollPane1); + jScrollPane1.setBounds(293, 100, 207, 406); + + jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N + jLabel2.setText("Remote IP Address"); + getContentPane().add(jLabel2); + jLabel2.setBounds(23, 66, 134, 17); + + ipTextField.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + ipTextFieldActionPerformed(evt); + } + }); + getContentPane().add(ipTextField); + ipTextField.setBounds(20, 90, 190, 40); + + ActionButton.setText("Action"); + ActionButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + ActionButtonActionPerformed(evt); + } + }); + getContentPane().add(ActionButton); + ActionButton.setBounds(290, 510, 210, 40); + + pack(); + }// //GEN-END:initComponents + + private void ipTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ipTextFieldActionPerformed + + }//GEN-LAST:event_ipTextFieldActionPerformed + + private void ActionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ActionButtonActionPerformed +String ip=ipTextField.getText(); +String cmd=(String)UtilityList.getSelectedValue(); +try{ +Socket socket=new Socket(ip,9090); +PrintStream out=new PrintStream(socket.getOutputStream()); +out.println(cmd); +out.close(); +socket.close(); +}catch(Exception e){e.printStackTrace();} + + }//GEN-LAST:event_ActionButtonActionPerformed + + private void UtilityListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_UtilityListValueChanged + + + + }//GEN-LAST:event_UtilityListValueChanged + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + /* Set the Nimbus look and feel */ + // + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html + */ + try { + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { + if ("Nimbus".equals(info.getName())) { + javax.swing.UIManager.setLookAndFeel(info.getClassName()); + break; + } + } + } catch (ClassNotFoundException ex) { + java.util.logging.Logger.getLogger(UtilityProgram.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(UtilityProgram.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(UtilityProgram.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(UtilityProgram.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new UtilityProgram().setVisible(true); + } + }); + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton ActionButton; + private javax.swing.JList UtilityList; + private javax.swing.JTextField ipTextField; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JScrollPane jScrollPane1; + // End of variables declaration//GEN-END:variables +}