Need help
Hi friends,
here my source code below.
what i need, from the databse i want to read the images here.
import java.awt.*;
import java.sql.*;
import java.awt.Image.*;
import java.awt.event.*;
import java.net.*;
public class assignment6 extends Frame implements ActionListener, FocusListener
{
private Image image,image1;
Label l,l1,l2,l3,l4;
TextField t1;
Image t4;
TextArea t2,t3;
Button b4,b5,b6,b7;
Connection con;
ResultSet rs;
String str;
String sql;
Statement stat;
public assignment6()
{
super("Assignment: 6");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Zebra") ;
stat=con.createStatement();
}catch(Exception ex){}
setLayout(null);
//first line
l=new Label("Assignment No:6");
add(l);
l.setBounds(150,40,200,20);
l.setForeground(Color.ORANGE);
l.setBackground( Color.BLUE);
l.setAlignment( Label.CENTER );
l.setFont( new Font ( "Dialog", 15, Font.PLAIN ));
Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage("logo.gif");
image1 = toolkit.getImage("ijts.gif");
l4=new Label("Batch No:35");
add(l4);
l4.setBounds(150,60,200,20);
l4.setAlignment( Label.CENTER );
l1=new Label("Question Id:");
add(l1);
l1.setBounds(10,120,100,20);
t1=new TextField("1");
add(t1);
t1.setBounds(110,120,160,20);
t1.addFocusListener(this);
//second line
l2=new Label("Question:");
add(l2);
l2.setBounds(10,140,100,20);
t2=new TextArea();
add(t2);
t2.setBounds(10,160,480,120);
// third line
l3=new Label("Answers:");
add(l3);
l3.setBounds(10,290,100,20);
t3=new TextArea();
add(t3);
t3.setBounds(10,310,480,220);
//GO button
b4=new Button("Go");
add(b4);
b4.addActionListener(this);
b4.setBounds(300,120,25,20);
//Exit button
b5=new Button("Exit");
add(b5);
b5.addActionListener(this);
b5.setBounds(200,570,100,20);
b6=new Button("Next");
add(b6);
b6.addActionListener(this);
b6.setBounds(310,570,100,20);
b7=new Button("Previous");
add(b7);
b7.addActionListener(this);
b7.setBounds(90,570,100,20);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b5)
{
System.exit(0);
}
else if(e.getSource()==b6)
{
onNext();
}
else if(e.getSource()==b7)
{
onPrevious();
}
}
public void focusGained(FocusEvent e){}
public void focusLost(FocusEvent e)
{
if(e.getSource()==t1)
{
onSelect();
}
}
public void onSelect()
{
String newid=t1.getText();
sql="select * from Assignment where QID="+ newid +"";
try{
rs=stat.executeQuery(sql);
if (rs.next())
{
t2.setText(rs.getString(2));
t3.setText(rs.getString(3));
}
}catch(Exception ex){}
}
public void onNext()
{
str=t1.getText();
int i = Integer.parseInt(str);
i=i+1;
String val =""+i;
t1.setText(val);
onSelect();
}
public void onPrevious()
{
str=t1.getText();
int j = Integer.parseInt(str);
j=j-1;
String val =""+j;
t1.setText(val);
onSelect();
}
public void paint(Graphics graphics) {
graphics.drawImage(image, 10, 30, this);
graphics.drawImage(image1, 400, 50, this);
}
public static void main(String args[])
{
assignment6 da1;
da1=new assignment6();
da1.setSize(500,600);
da1.show();
}
}
surendran
(Anything is Possible)
__________________
surendran
(Anything is Possible)
http://www.suren.info
http://ssuren.spaces.msn.com
|