gui display data retrieve from database...Urgent
i have a gui file and a database file file.... i need to display the data from my database in my gui.....i'm stuck...the program is error free...i just dunno the next move?......is it something to do with accessor and mutator method?
package gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class gui extends JFrame implements ActionListener
{
private JButton Yes;
private JButton No;
private JButton How;
private JButton Why;
private JTextArea Question;
private JTextArea Answer;
public gui()
{
buildGui();
pack();
setSize(600,400);
setLocation(200,150);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void buildGui()
{
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
Yes = new JButton("Yes");
Yes.addActionListener(this);
No = new JButton("No");
No.addActionListener(this);
How = new JButton("How");
How.addActionListener(this);
Why = new JButton("Why");
Why.addActionListener(this);
JPanel inputPanel = new JPanel();
inputPanel.add(Yes);
inputPanel.add(No);
inputPanel.add(How);
inputPanel.add(Why);
contentPane.add("South", inputPanel);
How.setEnabled(false);
Why.setEnabled(false);
Question = new JTextArea(3,10);
contentPane.add("North", Question);
Answer = new JTextArea(3,10);
contentPane.add("Center", Answer);
Question.setBackground(new Color(0xe0e0e0));
Answer.setBackground(new Color(0xe0e0e0));
Question.setEditable(false);
Answer.setEditable(false);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Yes)
{
How.setEnabled(false);
Why.setEnabled(false);
}
else
{
How.setEnabled(true);
Why.setEnabled(true);
Question.getText();
}
}
public static void main(String args[])
{
new gui();
ES es;
es = new ES();
es.db();
}
}
package gui;
import java.sql.*;
public class ES {
public void db(){
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception E) {
System.err.println("Unable to load driver");
E.printStackTrace();
}
try {
Connection C = DriverManager.getConnection(
"jdbc:mysql://localhost/answer", "root", "root");
Statement Stmt = C.createStatement();
ResultSet RS = Stmt.executeQuery
("SELECT question " +
" FROM Question WHERE QuestionNo='1'");
while (RS.next()) {
System.out.println(RS.getString(1));
}
C.close();
RS.close();
Stmt.close();
}
catch (SQLException E) {
System.out.println("SQLException: " + E.getMessage());
}
}
}

