mport java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Frame1 extends JFrame {
private static final String text = "<html> <center><b><font size=+3>Central</font></b> <br><b><font size=+3>Manager</font></b></center> </html>";
JPanel jPanel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JLabel jLabel1 = new JLabel();
JPanel jPanel2 = new JPanel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JTextField loginTextField = new JTextField(20);
JPasswordField passwordTextField = new JPasswordField(20);
JPanel jPanel3 = new JPanel();
JButton exitButton = new JButton();
JButton enterButton = new JButton();
FlowLayout flowLayout1 = new FlowLayout();
public Frame1() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void login(ActionEvent e) {
String login = loginTextField.getText();
String password = new String(passwordTextField.getPassword());
//validate login and password here. validity will be done by sending login/password to the server
if (login.equals("raman") && password.equals("raman")) {
System.out.println("login successfull");
showTreeView();
} else {
JOptionPane.showMessageDialog(this,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
loginTextField.setText("");
passwordTextField.setText("");
loginTextField.requestFocusInWindow();
}
}
private void showTreeView() {
getContentPane().removeAll();
TreeViewPanel treeview = new TreeViewPanel();
getContentPane().add(treeview);
getContentPane().validate();
}
private void exit(ActionEvent e) {
setVisible(false);
}
public static void main(String[] args) {
Frame1 f = new Frame1();
f.setLocation(200,200);
f.pack();
f.show();
}
private void jbInit() throws Exception {
jPanel1.setLayout(borderLayout1);
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
jLabel1.setText(text);
jPanel2.setLayout(gridBagLayout1);
jLabel2.setText("Password:");
jLabel3.setText("Login:");
exitButton.setText("Exit");
exitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
exit(e);
}
});
enterButton.setText("Enter");
enterButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
login(e);
}
});
jPanel3.setLayout(flowLayout1);
flowLayout1.setAlignment(FlowLayout.RIGHT);
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jLabel1, BorderLayout.NORTH);
jPanel1.add(jPanel2, BorderLayout.CENTER);
jPanel2.add(loginTextField, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 11, 0, 0), 0, 0));
jPanel2.add(jLabel2, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(11, 0, 0, 0), 0, 0));
jPanel2.add(passwordTextField, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(11, 11, 0, 0), 0, 0));
jPanel2.add(jLabel3, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
jPanel1.add(jPanel3, BorderLayout.SOUTH);
jPanel3.add(enterButton, null);
jPanel3.add(exitButton, null);
}
}
==================================
import java.awt.*;
import javax.swing.*;
public class TreeViewPanel extends JPanel {
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JTree tree = new JTree();
JPanel jPanel1 = new JPanel();
JButton jButton1 = new JButton();
public TreeViewPanel() {
try {
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
void jbInit() throws Exception {
this.setLayout(borderLayout1);
jButton1.setText("Manage Group");
this.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(tree, null);
this.add(jPanel1, BorderLayout.SOUTH);
jPanel1.add(jButton1, null);
}
}