File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes how to do graphical poll creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to do graphical poll creation" Watch "how to do graphical poll creation" New topic
Author

how to do graphical poll creation

hrishih punekar
Greenhorn

Joined: Jan 08, 2013
Posts: 13
I have done following code for poll creation where users votes are counted. And I want show the votes in poll format ie. in graphical format. How to do so.
code:


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

import sun.security.krb5.internal.LastReqEntry;


public class polling1 extends HttpServlet implements ActionListener{
private static final long serialVersionUID = 1L;

Connection con;
Statement st;
ResultSet rs;
PreparedStatement ps;
int r1_count=0;
int r2_count=0;
JFrame f=new JFrame();
JButton submit=new JButton("SUBMIT");
JRadioButton r1=new JRadioButton("SAKAL");
JRadioButton r2=new JRadioButton("TIMES");
ButtonGroup g=new ButtonGroup();

public void init(ServletConfig config) throws ServletException {

try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbcracle:thin:@localhost:1521:ORACLE11","scott","tiger");
st=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//rs=st.executeQuery("select * from registration");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



f.setLayout(null);
r1.setBounds(200,200,150,50);
r2.setBounds(200,300,150,50);
submit.setBounds(200,400,150,30);
r1.addActionListener(this);
r2.addActionListener(this);
submit.addActionListener(this);
}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
f.setBounds(500,500,500,500);
r1.setSelected(false);
r2.setSelected(false);
g.add(r1);
g.add(r2);
f.add(r1);
f.add(r2);
f.add(submit);
f.setVisible(true);
}


@Override
public void actionPerformed(ActionEvent e) {

if(e.getSource()==submit)
{



if(r1.isSelected()==true)
{
try {
rs=st.executeQuery("select * from poll order by count1");
rs.last();

System.out.println(rs.getInt(1));
int count1=rs.getInt(1);
//System.out.println(count1);
count1++;

ps=con.prepareStatement("insert into poll values(?,?)");
ps.setInt(1,count1);
ps.setInt(2,0);

int numRowsChanged=ps.executeUpdate();
//ps.setInt(2, 0);



} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
r1_count++;
//System.out.println("Sakal"+r1_count);
//System.out.println("Times"+r2_count);
}




if(r2.isSelected()==true);

{

try {
rs=st.executeQuery("select * from poll order by count2");
rs.last();

//System.out.println(rs.getInt(2));
int count2=rs.getInt(2);
System.out.println(count2);
count2++;

ps=con.prepareStatement("insert into poll values(?,?)");
ps.setInt(1, 0);
ps.setInt(2,count2);

int numRowsChanged=ps.executeUpdate();
//ps.setInt(2, 0);



} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
r2_count++;
}



}
}
}





 
GeeCON Prague 2014
 
subject: how to do graphical poll creation