
hi., i just need to correct my codes.somebody help me to clear the error to bring a right of codes to execute.Thanks in advance.
//first page
import java.awt.*;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class gwf extends Frame implements ActionListener
{
public Label l1,l2,l3;
public TextField tf1,tf2,tf3;
public JComboBox c1,c2;
public Button b1,b2;
public Panel p1,p2;
String s1,s2;
gwf()
{ setLayout(new GridLayout(5,1));
setTitle("FIRST PAGE");
l1 = new Label("Choose Department");
c1 = new JComboBox();
c1.addItem("--select--");
c1.addItem("Welfare");
c1.addItem("Revenue");
c1.addItem("State office");
c1.addItem("Public");
c1.addItem("Corporation");
p1 = new Panel();
p2 = new Panel();
b1 = new Button("SUBMIT");
p1.add(l1);
p1.add(c1);
p2.add(b1);
add(p1, "Center");
add(p2, "South");
b1.addActionListener(this);
setSize(500, 500);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
gwf1 gw = new gwf1(s1);
dispose();
}
public static void main(String[] args) throws SQLException
{
gwf g = new gwf(); }
//second page
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
class gwf1 extends Frame implements ActionListener
{
private static final String String =null;
Label l1;
TextField t1;
JComboBox c1,c2;
Panel p1,p2;
Button b1;
String s1, s2;
Statement st;
ResultSet rs;
Connection con;
public void apply()
{
try
{
Class.forName("org.postgresqlANSI.Driver");
con = DriverManager.getConnection("jdbc:postgresqlANSI://localhost:5432/departments","postgres", "postgres");
ResultSet rs=st.executeQuery("SELECT role_name from role WHERE dept_id=1234");
if(rs!=null)
{while(rs.next())
{
c1.addItem(rs.getString("role_name"));
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public gwf1(String s1)
{
this.s1 = s1;
setLayout(new GridLayout(5, 1));
setTitle("Second Page");
l1 = new Label("Enter Role");
c1 = new JComboBox();
c1.addItem("--select--");
b1 = new Button("SUBMIT");
p1 = new Panel();
p2 = new Panel();
p1.add(l1);
p1.add(c1);
p2.add(b1);
add(p1, "Center");
add(p2, "South");
b1.addActionListener(this);
setSize(400, 500);
setVisible(true);
}
public void actionPerformed(ActionEvent e1)
{
JOptionPane.showMessageDialog(this, "The generated Id is:");
dispose();
gwf2 gp = new gwf2();
}
}

We have used Mysql database:
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class JComboBoxExample{
public static void main(String[] args){
JFrame f=new JFrame();
f.setLayout(null);
JLabel lab=new JLabel("Course Items:");
final JComboBox combo=new JComboBox();
combo.addItem("--Select--");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from student");
while(rs.next()){
combo.addItem(rs.getInt("id"));
}
}
catch(Exception e){}
JButton b=new JButton("Get");
lab.setBounds(20,20,100,20);
combo.setBounds(120,20,150,20);
b.setBounds(120,50,80,20);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String value = combo.getSelectedItem().toString();
JOptionPane.showMessageDialog(null,"You have selected '"+value+"' from ComboBox");
}
});
f.add(lab);
f.add(combo);
f.add(b);
f.setVisible(true);
f.setSize(300,120);
}
}
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.