java code implementation

java code implementation

View Answers

October 27, 2009 at 4:09 PM

Hi Friend,

Try the following code:

1)VoteCounter.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class VoteCounter{
public static void main(String[] args){
JFrame frame = new JFrame("Vote Counter");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 200);

JPanel panel1= new JPanel();
panel1.setPreferredSize(new Dimension (150, 50));
JLabel label1 = new JLabel ("James");
panel1.add(label1);

JPanel panel2 = new JPanel();
panel2.setPreferredSize(new Dimension (150, 50));
JLabel label2 = new JLabel ("Sally");
panel2.add(label2);

JLabel label=new JLabel("Vote Now.............");
JPanel panel= new JPanel();
panel.setBackground(Color.blue);
panel.add(panel1);
panel.add(panel2);
panel.add(label);
frame.getContentPane().add(panel, "Center");
frame.getContentPane().add(new VoteCounterPanel(), "South");
frame.setVisible(true);
}
}

2)VoteCounterPanel.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class VoteCounterPanel extends JPanel {
int james=0;
int sally=0;
JLabel label;
JButton button1;
JButton button2;
JButton button;

public VoteCounterPanel(){
label=new JLabel();
button1= new JButton("Vote for James");
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {
james++;
if(james>sally){
label.setText("James is winning......");
}
else{
label.setText("Sally is winning......");
}
System.out.println("Votes for James" + james);
}
});

button2= new JButton("Vote for Sally");
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {
sally++;
if(james>sally){
label.setText("James is winning......");
}
else{
label.setText("Sally is winning......");
}
System.out.println("Votes for Sally"+ sally);
}
});
add(button1);
add(label);
add(button2);
}
}
Thanks


October 27, 2009 at 4:37 PM

Thanks. I got my code to work ok. But your code helps clarify the confusion I had earlier

October 27, 2009 at 4:38 PM

Thanks. I got my code to work ok. But your code helps clarify the confusion I had earlier









Related Tutorials/Questions & Answers:
java code implementation - Java Beginners
java code implementation  I am writing a java program, voteCounter... Friend, Try the following code: 1)VoteCounter.java import java.awt....;Thanks. I got my code to work ok. But your code helps clarify the confusion I had
Stack Implementation java code - Java Beginners
Stack Implementation java code  Hello roseindia and java experts can u help me.can you give me a code for this sir/maam.thank you so much. STACK IMPLEMENTATION -expression evaluator *GIVEN a String of expression, create
Advertisements
java native implementation
java native implementation  What is java native implementation
filter implementation in java
filter implementation in java   How to implement filters in java?   Java - filter implementation Tutorials Filter Files in Java Response Filter Servlet Example
java implementation - Java Beginners
java implementation  Im M.Phil research scholar,i need a software testing module implemented in java.My research area is software testing,if anyone could help me out
java implementation problem
java implementation problem   I want to implement following in java code : Main thread Create three threads wait for completion of stage 2 of all three threads Access all three local variable (LC0, LC1, LC2) of threads bulid
Java implementation problem
Java implementation problem  I want to implement following in java code : Main thread 1. create three threads 2. wait for completion of stage 2.../answers/viewqa/Java-Beginners/28578-java-implementation-problem-.html
java interfaces implementation
java interfaces implementation  hai I have defined one inter face... different implementation classes for add() method and sub()and mul() when i trying... which are define in Maths interface. I want only addition implementation
Question in Array Implementation (java) ??!
Question in Array Implementation (java) ??!  Good Morning EveryOne I have Q in Java - and if any One have the Answers please tall me ??!! Question is : 1- Create a class called â??PhoneEntryâ?? which can be used to store
garbage collection implementation dependent java
garbage collection implementation dependent java  How a garbage collection works in Java
Progress Bar implementation in Java Script
Progress Bar implementation in Java Script  Hi Friend, I am new to Java Script, but i want implement the progress bar in my html by reading the value from file (like value=30) and the value in file be changing from 0 to 100
linked lists implementation - Java Beginners
, there are no preconditions. Write the code for the method for a linked implementation (without tail reference), your code should be efficient. 2. What changes would you do
Simple Hash Table implementation in Java
Simple Hash Table implementation in Java   ... implementation from the basic in Java. In this section, you will see how... the given title exists or not. This section is very helpful for your java
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles
java code
java code  what is the code to turn off my pc through java program
JAVA CODE
JAVA CODE  JAVA SOURCE CODE TO BLOCK A PARTICULAR WEB SITES(SOCIAL WEB SITE
java code
java code  write a java code to convert hindi to english using arrays
java code
java code  hi any one please tell me the java code to access any link i mean which method of which class is used to open any link in java program
java code
java code  need java code for chart or graph which compare the performance of aprior algorithm and coherent rule algorithm.plz any one help me out
java code
java code  write a java code for finding a string in partiular position in a delimited text file and replace the word with the values given by user and write the file in new location
java code
java code  sir how to merge the cells in excel using java code please help me and also how to make the text placed in the cell to be center
java code
java code  sir how to merge the cells in excel using java code please help me and also how to make the text placed in the cell to be center
java code
java code  I need the java code that would output the following: HARDWARE ITEMS CODE DESCRIPTION UNIT PRICE K16 Wood screws,brass,20mm $7.75 D24 Wood glue,clear,1 liter $5.50 M93
Java code
Java code   Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes
java code
java code  develop a banking system in java
java code
java code  HOW TO PRINT 1 TO 100 WITHOUT USING CONDITIONAL,ANY LOOP AND ARRAY IN JAVA AND C.URGENT SIR PLZ  Hi, You can use following code: class MyClass { public static void main(String[] args) { int
java code
java code  how to extract html tags using java
Java code
Java code  Write a program which performs to raise a number to a power and returns the value. Provide a behavior to the program so as to accept any... the following code: import java.util.*; import java.text.*; class NumberProgram
java code
java code  int g() { System.out.println("Inside method g"); int h() { System.out.println("Inside method h"); } } Find the error in the following... cannot define a method inside another method. Anyways, we have modified your code
java code
java code  what is meaning bufferedreader
java code
java code  what is meaning bufferedreader
java code
java code  i want HSVcolor descriptor for color image in java coding
Java code
Java code  An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus...; Hi Friend, Try the following code: import java.util.*; import
Java code
Java code   Create a calculator class which will have methods add, multiply, divide & subtract   Hi Friend, Try the following code: class Calculation{ public int add(int a,int b){ return a+b
java code
java code  I am beginer in java my question is how can i fill data from mysql database to jcombobox using netbeans
Java Code
Java Code  Write a java program, which creates multiple threads. Each thread performs add/delete/update operations on an ArrayList simultaneously
java code
java code  hi, Can any one tell me " How to read the data which is present om an image in java
java code
java code  Write a program in java for lru caching using two inputs one using integer and another using string of uppercase only
Java code
Java code  Create a class called Student which has the following methods: i. Average: which would accept marks of 3 examinations & return... & returns the name.   Hi Friend, Try the following code: import
Java code
Java code  Create a Bank class with methods deposit & withdraw. The deposit method would accept attributes amount & balance & returns....   Hi Friend, Try the following code: import javax.swing.*; class
Java code
Java code   Create an Employee class which has methods netSalary which would accept salary & tax as arguments & returns the netSalary which... the following code: import java.util.*; class Employee { static Scanner input=new
java code
java code  An employee _id consist of 5 digits is stored in a string variable strEmpid. Now Mr.Deb wants to store this Id in Integer type to IntEmpid. write Java statements to do
java code
java code  Write a program to find the difference between sum of the squares and the square of the sums of n numbers
java code
java code   Develop a program that accepts the area of a square and will calculate its perimeter
java code
java code  Create a calculator class which will have methods add, multiply, divide & subtract
java code
java code  input any word ie risk,resul is-- r ri ris risk
Java code
Java code  Create Book having following attributes: Book ID, Title, Author and Price. Create Periodical which has the following additional attributes... Friend, Try the following code: import java.util.*; class Book{ int id
java code
java code  Develop the program calculateCylinderVolume., which accepts radius of a cylinder's base disk and its height and computes the volume of the cylinder
java code
java code  Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder
java code
java code  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes

Ads