Please do help me!!!!
package sage;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.*;
import javax.swing.tree.TreeModel;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultMutableTreeNode;
import org.apache.xerces.parsers.SAXParser;
public class Login extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
JButton OK;
JButton Cancel;
JPanel panel;
JLabel banner;
JTextField text1, text2;
JLabel label1, label2, label3, label4;
private Object e;
private String sessionToken;
private Object token;
private String p;
private String wordString;
private Object answer;
public String tokenValue;
public String abc;
public String id , name;
public String str1;
public Login() {
JFrame frame = new JFrame("Login");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(null);
JLabel banner = new JLabel("Login");
banner.setFont(new Font("SansSerif", Font.BOLD, 28));
banner.setBackground(Color.lightGray);
banner.setForeground(Color.WHITE);
banner.setOpaque(true);
banner.setPreferredSize(new Dimension(100, 1000));
JLabel label4 = new JLabel("Enter your user name and Password");
label4.setFont(new Font("SansSerif", Font.BOLD, 14));
JLabel label1 = new JLabel("Name");
label1.setFont(new Font("SansSerif", Font.PLAIN, 12));
JTextField field1 = new JTextField(20);
JLabel label2 = new JLabel("Password");
label2.setFont(new Font("SansSerif", Font.PLAIN, 12));
JPasswordField field2 = new JPasswordField(20);
JCheckBox chk = new JCheckBox("Remember Password");
chk.setFont(new Font("SansSerif", Font.PLAIN, 12));
JButton button1 = new JButton("OK");
JButton button2 = new JButton("Cancel");
banner.setBounds(10, 10, 440, 35);
label4.setBounds(20, 50, 400, 50);
label1.setBounds(60, 90, 100, 50);
field1.setBounds(140, 100, 200, 25);
label2.setBounds(60, 130, 120, 50);
field2.setBounds(140, 150, 200, 25);
chk.setBounds(50, 180, 300, 50);
button1.setBounds(230, 230, 100, 25);
button2.setBounds(350, 230, 100, 25);
panel.add(banner);
panel.add(label4);
panel.add(label1);
panel.add(label2);
panel.add(field1);
panel.add(field2);
panel.add(chk);
panel.add(button1);
panel.add(button2);
frame.add(panel);
frame.setSize(470, 300);
frame.setVisible(true);
frame.setResizable(false);
button1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
String data = "username & Password ";
String line = "";
try {
// Send the request
URL url = new URL(
"http://dakota-msiley.cwru.edu/remote/login/superman4@example.com/swordfish");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.
getOutputStream());
// Get the response
StringBuffer answer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
while ((line = reader.readLine()) != null) {
answer.append(line);
}
writer.close();
reader.close();
//Output the response
System.out.println(answer.toString());
String str = answer.toString();
tokenValue = str.substring(str.indexOf("<token>") + 7,
str.indexOf("</token>"));
System.out.println(tokenValue);
sendPostRequest();
} catch (MalformedURLException ex) {
} catch (IOException ex) {
}
}
/**
* XMLTreeView
*/
// private void XMLTreeView() {
// }
// login - hit OK
// http://dakota-swetha.cwru.edu/remote/login/superman4@example.com/swordfish
// <token>LKJLJFDKJ</token>
// set token in an instance variable
public void sendPostRequest() {
String data = "username & Password ";
String line = "";
try {
// Send the request
URL url = new URL(
"http://dakota-msiley.cwru.edu/remote/workspaces/" +
tokenValue);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
//write parameters
// Get the response
// StringBuffer answer = new StringBuffer();
StringBuffer answer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
while ((line = reader.readLine()) != null) {
answer.append(line);
}
//Output the response
System.out.println(answer.toString());
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//root.add(workspaces);
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args) {
Login login = new Login();
}
When I execute this : I get a Login frame with a login and password fields , i enter them and i get hte output as
<?xml version="1.0" encoding="UTF-8" ?><login> <token>Cs072tMCQ9f1z9bu7fCP</token></login>
Cs072tMCQ9f1z9bu7fCP
<?xml version="1.0" encoding="UTF-8" ?><workspaces> <workspace> <id>1</id> <name>Mike Siley</name> <workspaces> <workspace> <id>16</id> <name>Child WS</name> <workspaces> <workspace> <id>17</id> <name>Child 1</name> <workspaces> <workspace> <id>18</id> <name>Child 2</name> </workspace> </workspaces> </workspace> </workspaces> </workspace> </workspaces> </workspace> <workspace> <id>9</id> <name>Test me 35</name> <workspaces> <workspace> <id>34</id> <name>Daughter</name> <workspaces> <workspace> <id>41</id> <name>Another Child</name> </workspace> </workspaces> </workspace> <workspace> <id>52</id> <name>Test Child</name> </workspace> </workspaces> </workspace> <workspace> <id>11</id> <name>Test me 35</name> </workspace> <workspace> <id>13</id> <name>WS 84</name> </workspace> <workspace> <id>14</id> <name>WS 87</name> </workspace> <workspace> <id>15</id> <name>WS 8383</name> </workspace> <workspace> <id>39</id> <name>Test WS 101</name> </workspace> <workspace> <id>53</id> <name>KCC_TEST_11JAN2011</name> <workspaces> <workspace> <id>54</id> <name>ASCHNELL</name> <workspaces> <workspace> <id>55</id> <name>kccws</name> </workspace> </workspaces> </workspace> </workspaces> </workspace></workspaces>
Attached File(s)
-
login _dates latestttt.txt (6.43K)
Number of downloads: 42

New Topic/Question
Reply



MultiQuote





|