[Consider the program below]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package scheduling;
/**
*
* @author ThankGod
*/
import javax.swing.*;
import java.awt.event.*;
public class DualQuery extends JFrame implements ActionListener
{
JMenuBar jmb = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem exe = new JMenuItem("Execute Query",new ImageIcon("execute.jpg"));
JPanel querypanel = new JPanel();
JPanel resultpanel = new JPanel();
JTextArea textArea = new JTextArea(10,60);
JLabel resultlabel = new JLabel(" Query Result");
public DualQuery()
{
textArea.setText("Query");
resultpanel.add(resultlabel);
exe.addActionListener(this);
file.add(exe);
jmb.add(file);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setVerticalScrollBarPolicy(JScrollPane. VERTICAL_SCROLLBAR_ALWAYS);
querypanel.add(scrollPane);
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, querypanel, resultpanel);
splitPane.setOneTouchExpandable(true);
getContentPane().add(splitPane);
setSize(700, 650);// here's the part where i center the jframe on screen
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}//end of constructor
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==exe){
//Executing Engine here
MySQLController mysql = new MySQLController(resultpanel,textArea.getText());
}
}//end main
}
public class MySQLController(JPanel panel,String query){
JLabel fname = new JLabel("First Name:");
JTextField nametf = new JTextField();
public MySQLControler(){
panel.add(fname);
panel.add(namef);
jpanel.add(fname);
}
}
1. I want the content of the firstname label and text field from the MySQLController class to automatically updated in the DualQuery class when a user click on execute menuitem But its not given me the desired result
2. Is it possible to make the JTextArea's size adjust automatically when the user adjust the splitpane up and down?