import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.sql.*;
public class panel extends JFrame implements ActionListener {
ResultSet res;
Connection conn;
Statement stat;
String lang;
JFrame frame = new JFrame("Graphics Button");
lang="abc";
JButton b1;
JLabel l1,l2,l3;
JPanel p,p1,p2,p3,p4;
p.setSize(100,100);
p.setLayout(new GridLayout(3,0));
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
l1=new JLabel(lang);
l2=new JLabel();
l3=new JLabel();
ImageIcon button=new ImageIcon("magnifier1.jpg");
b1=new JButton();
b1.setIcon(button);
b1.setOpaque(false);
b1.setFocusPainted(false);
b1.setBorderPainted(false);
b1.setContentAreaFilled(false);
b1.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
b1.setBorderPainted(false);
b1.addActionListener(this);
b1.setBackground(Color.green);
//b2=new JButton("cancel");
p1.setBackground(Color.black);
p1.add(l1);
p2.setBackground(Color.green);
p3.setBackground(Color.red);
p4.setBackground(Color.blue);
p.add(p1);
p.add(p2);
p.add(p3);
p4.add(b1);
//p4.add(b2);
frame.add(p,BorderLayout.CENTER);
frame.add(p4,BorderLayout.SOUTH);
frame.pack();
frame.setVisible(true);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:guru","","");
stat = conn.createStatement();
res = stat.executeQuery("Select * from hotel");
res.next();
//con.close();
}
catch(Exception e)
{
e.printStackTrace();
}//end of try
public void actionPerformed(ActionEvent e) {
if(e.getSource() == b1) {
try {
res.next();
}
catch(Exception ee) {}//end of try
showRecord(res);
}//end if
}//end action performed
public void showRecord(ResultSet res) {
try {
l1.setText(res.getString(1));
l2.setText(res.getString(2));
}
catch(Exception e) {}//end try
}//end of show record
public static void main(String[] args) {
panel p=new panel();
p.showRecord(res);
}
}//end ma
/* errors:-
C:\>javac panel.java
panel.java:14: <identifier> expected
lang="abc";
^
panel.java:18: <identifier> expected
p.setSize(100,100);
^
panel.java:18: illegal start of type
p.setSize(100,100);
^
panel.java:19: <identifier> expected
p.setLayout(new GridLayout(3,0));
^
panel.java:19: illegal start of type
p.setLayout(new GridLayout(3,0));
^
panel.java:21: <identifier> expected
p1=new JPanel();
^
panel.java:22: <identifier> expected
p2=new JPanel();
^
panel.java:23: <identifier> expected
p3=new JPanel();
^
panel.java:24: <identifier> expected
p4=new JPanel();
^
panel.java:25: <identifier> expected
l1=new JLabel(lang);
^
panel.java:26: <identifier> expected
l2=new JLabel();
^
panel.java:27: <identifier> expected
l3=new JLabel();
^
panel.java:29: <identifier> expected
b1=new JButton();
^
panel.java:30: <identifier> expected
b1.setIcon(button);
^
panel.java:30: <identifier> expected
b1.setIcon(button);
^
panel.java:31: <identifier> expected
b1.setOpaque(false);
^
panel.java:31: illegal start of type
b1.setOpaque(false);
^
panel.java:32: <identifier> expected
b1.setFocusPainted(false);
^
panel.java:32: illegal start of type
b1.setFocusPainted(false);
^
panel.java:33: <identifier> expected
b1.setBorderPainted(false);
^
panel.java:33: illegal start of type
b1.setBorderPainted(false);
^
panel.java:34: <identifier> expected
b1.setContentAreaFilled(false);
^
panel.java:34: illegal start of type
b1.setContentAreaFilled(false);
^
panel.java:35: <identifier> expected
b1.setBorder(BorderFactory.createEmptyBord
^
panel.java:35: <identifier> expected
b1.setBorder(BorderFactory.createEmptyBord
panel.java:36: <identifier> expected
b1.setBorderPainted(false);
^
panel.java:36: illegal start of type
b1.setBorderPainted(false);
^
panel.java:37: <identifier> expected
b1.addActionListener(this);
^
panel.java:37: illegal start of type
b1.addActionListener(this);
^
panel.java:38: <identifier> expected
b1.setBackground(Color.green);
^
panel.java:38: <identifier> expected
b1.setBackground(Color.green);
^
panel.java:40: <identifier> expected
p1.setBackground(Color.black);
^
panel.java:40: <identifier> expected
p1.setBackground(Color.black);
^
panel.java:41: <identifier> expected
p1.add(l1);
^
panel.java:41: <identifier> expected
p1.add(l1);
^
panel.java:42: <identifier> expected
p2.setBackground(Color.green);
^
panel.java:42: <identifier> expected
p2.setBackground(Color.green);
^
panel.java:43: <identifier> expected
p3.setBackground(Color.red);
^
panel.java:43: <identifier> expected
p3.setBackground(Color.red);
^
panel.java:44: <identifier> expected
p4.setBackground(Color.blue);
^
panel.java:44: <identifier> expected
p4.setBackground(Color.blue);
^
panel.java:45: <identifier> expected
p.add(p1);
^
panel.java:45: <identifier> expected
p.add(p1);
^
panel.java:46: <identifier> expected
p.add(p2);
^
panel.java:46: <identifier> expected
p.add(p2);
^
panel.java:47: <identifier> expected
p.add(p3);
^
panel.java:47: <identifier> expected
p.add(p3);
^
panel.java:48: <identifier> expected
p4.add(b1);
^
panel.java:48: <identifier> expected
p4.add(b1);
^
panel.java:50: <identifier> expected
frame.add(p,BorderLayout.CENTER);
^
panel.java:50: <identifier> expected
frame.add(p,BorderLayout.CENTER);
^
panel.java:50: <identifier> expected
frame.add(p,BorderLayout.CENTER);
^
panel.java:51: <identifier> expected
frame.add(p4,BorderLayout.SOUTH);
^
panel.java:51: <identifier> expected
frame.add(p4,BorderLayout.SOUTH);
^
panel.java:51: <identifier> expected
frame.add(p4,BorderLayout.SOUTH);
^
panel.java:52: <identifier> expected
frame.pack();
^
panel.java:53: <identifier> expected
frame.setVisible(true);
^
panel.java:53: illegal start of type
frame.setVisible(true);
^
panel.java:55: illegal start of type
try
^
panel.java:65: illegal start of type
catch(Exception e)
^
panel.java:65: ';' expected
catch(Exception e)
^
61 errors
*/