Home Answers Viewqa Java-Beginners java code implementation

 
 


daniel
java code implementation
3 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners

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 Pages:
Implementation code inside interfaces
Implementation code inside interfaces 2001-01-25 The Java Specialists' Newsletter [Issue 006] - Implementation code inside interfaces Author: Dr. Heinz..., with more lines of pure Java code than the JDK 1.3, and actually paying me
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
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 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
jsp plugin implementation - Applet
code in my program as you given below. When I execute the above code in my client PC,it worked fine.But when I opened the same page in another..., Java BooksStore's   Java Bookstore
jsp plugin implementation - Applet
folder under the WEB-INF folder and put my java code file and its corresponding...jsp plugin implementation  Hi, I have implemented the code... NOT INITED error displayed in my status bar. I opened the java console. The error
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
Object-Oriented Implementation of Numerical Methods - Java Tutorials
Object-Oriented Implementation of Numerical Methods 2002-04-01 The Java Specialists' Newsletter [Issue 044] - Review: Object-Oriented Implementation...-written Java code, Dr. Besset also tackles issues such as the problems that happen
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
JDBC4.0-Dataset implementation of SQL using Annotations
to associate a SQL query with a Java class without writing a lot of code. We can also... all the code we usually write to populate the query result into a Java object. There are two main annotations when specifying SQL queries in Java code
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
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
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
String Class implementation in API
String Class implementation in API  Hi all, I was confused ,when am looking into java String class single argument constructor into that we are passing again String as parameter.How is it possible,any one can help me how can
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 list implementation
Linked list implementation  How to create linkedlist by using array in java? and also How to manipulate
PGP implementation - Security
PGP implementation  Hi sir, I have encounterd problem in writing the code for the PGP implementaion with mail compatibility,encrypting the messages.Can you provide the code for the PGP.It is very urgent
thread program for calculator implementation
thread program for calculator implementation  Hi i'm prem i need calculator progrm in java that are implemented by Thread interface.....pls strong text
Need acode for struts implementation - Struts
Need acode for struts implementation  I want a code to generate dynamic table with a text field and a drop down list and to retrieve that data in the action class and store in the data base
Steps For SSL Implementation/Enabling in Apache Tomcat 6.0
Steps For SSL Implementation/Enabling in Apache Tomcat 6.0   Hi , I am using the NetBeans 6.9 IDE Apache Tomcat 6.0 as Web server Front end jsp-servlet please gives me complete guidance steps ,code for SSL Implementation
Steps For SSL Implementation/Enabling in Apache Tomcat 6.0
Steps For SSL Implementation/Enabling in Apache Tomcat 6.0   Hi , I am using the NetBeans 6.9 IDE Apache Tomcat 6.0 as Web server Front end jsp-servlet please gives me complete guidance steps ,code for SSL Implementation
java code - Java Beginners
java code  how can get the intensity values of the image?how to divide the image into 8*8 blocks? (send me the implementation code in java)  import java.applet.*; import java.awt.*; import java.awt.image.*; public
RMI Client And RMI Server Implementation
RMI Client And RMI Server Implementation  ... result. The server code consists of an interface and a class. ..., is defined. This class is the implementation of the RMI interface. The RmiServer
code
code    how to write this in java
code
code   hi I need help in creating a java code that reminds user on a particular date about their festival. i have no clue of how to do it.. am looking forward to seek help from you
HTML5 input examples, Introduction and implementation of input tag.
HTML5 input examples, Introduction and implementation of input tag. Introduction:In this tutorial, you will see the use of input tag. The input tag...;<input  attributes /> Example of <input> in HTML5: Code
Circular queue implementation using array.
Code: #include <stdio.h> #define MAX 5 #include <stdlib.h> void insert(int queue[], int *rear, int front, int value) { *rear= (*rear +1...); } while(n == 1); } Output: Download this code
code
code  < comp xlink:type="new" xlink:actuate="onload"/> how to write this in java
Code
Code  how to print this?? with the use of only JSP....... 1 23 456 78910   Here is the jsp number pattern example: 1 2 3 4 5 6 7 8 9 10 <%@page language="java"%> <% int k = 1; for(int i=1; i<= 4 ;i
HTML5 source element, Implementation of &lt;source&gt; tag.
HTML5 source element, Implementation of <source> tag. Introduction:Here, we will see the implementation and use of <source> tag in HTML5...; in HTML5: Code: Source_Tag.html <!doctype html > <html > <
COMPORSYS Code Generation
COMPORSYS Code Generation COMPORSYS is expert in Software, we increase... by conception, implementation and maintenance of IT Solutions. Comporsys... for the frictionless implementation of the Software project. This contains the analysis
retrieve value from db in text box + calendar implementation.
retrieve value from db in text box + calendar implementation.  I have used http://www.roseindia.net/javascript/javascript-calendar.shtml code for implementing calendar in my project... It has calendar.html file in which
JAVA code For
JAVA code For   JAVA code For "Traffic signals Identification for vehicles
can i estimate estimate execution time for a method without knowing implementation details of a method - Java Interview Questions
can i estimate estimate execution time for a method without knowing implementation details of a method  hi all, can i estimate estimate execution time for a method without knowing implementation details of a method. Thanks
java code
java code  write a java code to convert hindi to english using arrays
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
Display a dialog box with Java Error
you a code that help you in implementation of dialog box with Java Error... the execution of a program using javaw ,the program code display a dialog box name Java... Display a dialog box with Java Error   
java code
java code  develop a banking system in java
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  how to extract html tags using java
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.