Jason Travis

Greenhorn
+ Follow
since Apr 05, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jason Travis

Sorry about the coding comming out like that...if someone knows how to post code such that it comes out readable please let me know...
18 years ago
Help, I am having trouble obtaining the low order bits for a socket on a port. The code is shown below. Any help would be greatly appreciated.
-Jason
import java.io.*;import java.net.*;import java.util.*;import javax.swing.*; public class FTPClient {private boolean pauser = false; //Used for wait returnprivate static final int CNTRL_PORT = 21;private Socket csock = null;private Socket dsock = null;private BufferedReader dcis;private PrintWriter pos; public FTPClient(String server, String user, String pass) { try { ftpConnect(server); ftpLogin(user, pass); } catch(IOException ioe) {System.err.println("Failed with connection to Server");} }private String responseParser(String resp) throws IOException {if (resp.substring(0,1).equals("1")) {pauser = true;return(resp);} else if (resp.substring(0,1).equals("2")) {pauser = false;return(resp);} else if ((resp.substring(0,1).equals("3")) | | (resp.substring(0,1).equals("4")) | | (resp.substring(0,1).equals("5"))) {return(resp);} else {return(null);}}public void ftpLogout() {try {pos.print("BYE\r\n");pos.flush();pos.close();dcis.close();csock.close();dsock.close();} catch (IOException e) {System.err.println("Error closing FTP: " + e.getMessage());}}private String ftpSendCmd(String cmd) throws IOException {if (pauser) {if (dcis != null) {String discard = dcis.readLine();pauser = false;}}pos.print(cmd + "\r\n");pos.flush();String response = responseHandler(cmd);return(response);}private String responseHandler(String cmd) throws IOException {String reply = this.responseParser(dcis.readLine());String numerals = reply.substring(0,3);String hyph_test = reply.substring(3,4);String next = null; if(hyph_test.equals("-")) { String tester = numerals + " "; boolean done = false; while(!done) { next = dcis.readLine(); while (next.equals("") | | next.equals(" ")) { next = dcis.readLine(); } if(next.substring(0,4).equals(tester)) done = true;} return next; } else return reply;} private Socket ftpGetDataSock() throws IOException { String reply = ftpSendCmd("PASV"); StringTokenizer st = new StringTokenizer(reply, ","); String[] parts = new String[6]; int i = 0; while(st.hasMoreElements()) { try { parts[ i ] = st.nextToken(); i++; } catch(NoSuchElementException nope){nope.printStackTrace();} } String[] possNum = new String[3]; for(int j = 0; j < 3; j++) { possNum[j] = parts[0].substring(parts[0].length() - (j + 1), parts[0].length() - j); if(!Character.isDigit(possNum[j].charAt(0))) possNum[j] = ""; } parts[0] = possNum[2] + possNum[1] + possNum[0]; String[] porties = new String[3]; for(int k = 0; k < 3; k++) { if((k + 1) <= parts[5].length()) porties[k] = parts[5].substring(k, k + 1); else porties[k] = "FOOBAR"; if(!Character.isDigit(porties[k].charAt(0))) porties[k] = ""; } parts[5] = porties[0] + porties[1] + porties[2]; String ip = parts[0]+"."+parts[1]+"."+parts[2]+"."+parts[3]; int port = -1; try { int big = Integer.parseInt(parts[4]) << 8; int small = Integer.parseInt(parts[5]); port = big + small; } catch(NumberFormatException nfe) {nfe.printStackTrace();} if((ip != null) && (port != -1)) dsock = new Socket(ip, port); else throw new IOException(); return dsock; } public void ftpSetTransferType(boolean asc) throws IOException { String ftype = (asc? "A" : "I"); ftpSendCmd("TYPE "+ftype); } private void ftpConnect(String server) throws IOException { csock = new Socket(server, CNTRL_PORT); InputStream cis = csock.getInputStream(); dcis = new BufferedReader(new InputStreamReader(cis)); OutputStream cos = csock.getOutputStream(); pos = new PrintWriter(cos, true); String numerals = responseHandler(null); if(numerals.substring(0,3).equals("220")) ; else System.err.println("Error connecting to ftp server."); } private void ftpLogin(String user, String pass) throws IOException { ftpSendCmd("USER "+user); ftpSendCmd("PASS "+pass); } private void ftpSetDir(String dir) throws IOException { ftpSendCmd("CWD "+dir); } private String getAsString(InputStream is) { int c=0; char lineBuffer[]=new char[128], buf[]=lineBuffer; int room= buf.length, offset=0; try { loop:while (true) { switch (c = is.read() ) { case -1: break loop; default: if (--room < 0) { buf = new char[offset + 128]; room = buf.length - offset - 1; System.arraycopy(lineBuffer, 0,buf, 0, offset); lineBuffer = buf; } buf[offset++] = (char) c; break; } } } catch(IOException ioe) {System.err.println("Error in getAsStrig." + ioe.getMessage());//ioe.printStackTrace();} if ((c == -1) && (offset == 0)) { return null; } return String.copyValueOf(buf, 0, offset); } public String download(String dir, String file) throws IOException { return download(dir, file, true); } public String download(String dir, String file, boolean asc) throws IOException { ftpSetDir(dir); ftpSetTransferType(asc); dsock = ftpGetDataSock(); InputStream is = dsock.getInputStream(); ftpSendCmd("RETR "+file); String contents = getAsString(is); ftpLogout(); return contents; } public void append(String dir, String file, String what, boolean asc) throws IOException { ftpSetDir(dir); ftpSetTransferType(asc); dsock = ftpGetDataSock(); OutputStream os = dsock.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); ftpSendCmd("APPE "+file); dos.writeBytes(what); dos.flush(); dos.close(); ftpLogout(); } public void upload(String remotedir, String file, String localdir, boolean asc, JProgressBar progbar) throws IOException {//Check if file is OKint inc = 0;progbar.setMinimum(0);progbar.setValue(0);progbar.update(progbar.getGraphics());File ftpFile = new File(localdir + "\\" + file);if (!ftpFile.isFile()) {throw new IOException("FTP file does not exist."); }RandomAccessFile raf = new RandomAccessFile(ftpFile,"r");progbar.setMaximum(((int)raf.length())); ftpSetDir(remotedir); ftpSetTransferType(asc); dsock = ftpGetDataSock(); OutputStream os = dsock.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); ftpSendCmd("STOR "+file);int idata = 0;while (true) {idata = raf.read();if (idata != -1) {dos.writeByte(idata);} else {break;}if (progbar!=null) {++inc;if (inc > 20) {progbar.setValue(progbar.getValue() + 20);progbar.update(progbar.getGraphics());inc = 0;}}} dos.flush(); dos.close(); } public String delete(String dir, String File) throws IOException { ftpSetDir(dir); return(ftpSendCmd("DELE "+ File)); } public String getList(String dir) throws IOException { ftpSetDir(dir); ftpSetTransferType(true); dsock = ftpGetDataSock(); InputStream is = dsock.getInputStream(); ftpSendCmd("LIST"); String contents = getAsString(is); return contents;}public String getNlst(String dir) throws IOException {ftpSetDir(dir);ftpSetTransferType(true);dsock = ftpGetDataSock(); InputStream is = dsock.getInputStream(); ftpSendCmd("NLST"); String contents = getAsString(is); return contents;}}
18 years ago
The problem is that under Win2K you can actually perform either a mouse click on say the Submit button or hit the enter key to perform the same event. However, I moved the jar file over to the Solaris 8 system and ran the program and the application would not recognize the enter key (when pressed) as an action event. The application would simply do nothing.
I appreciate all you help. Thank you for your suggestions.
18 years ago
What follows is the code you requested...
public class LoginFrame extends JFrame {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JLabel jLabelUserName = new JLabel();
JLabel jLabelPassword = new JLabel();
JPasswordField jPasswordField = new JPasswordField();
JTextField jUserNameField = new JTextField();
JButton QuitButton = new JButton();
JPanel jPanel2 = new JPanel();
JButton SubmitButton = new JButton();
JPanel jPanel3 = new JPanel();
JPanel jPanel4 = new JPanel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridBagLayout gridBagLayout2 = new GridBagLayout();
GridBagLayout gridBagLayout3 = new GridBagLayout();
GridBagLayout gridBagLayout4 = new GridBagLayout();
GridBagLayout gridBagLayout5 = new GridBagLayout();
private Object x = this;
boolean resizable = false;
boolean generateNotification90 = false;
boolean generateNotification91 = false;
boolean generateNotification92 = false;
/**Construct the frame*/
public LoginFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(400, 300));
this.setResizable(resizable);
this.setTitle("Login");
jPanel1.setLayout(gridBagLayout2);
jLabelUserName.setToolTipText("");
jLabelUserName.setHorizontalAlignment(SwingConstants.CENTER);
jLabelUserName.setHorizontalTextPosition(SwingConstants.RIGHT);
jLabelUserName.setText("User Name");
jLabelPassword.setToolTipText("");
jLabelPassword.setHorizontalAlignment(SwingConstants.CENTER);
jLabelPassword.setHorizontalTextPosition(SwingConstants.CENTER);
jLabelPassword.setText("Password");
jPanel1.setToolTipText("");
QuitButton.setText("Exit");
QuitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
QuitButton_actionPerformed(e);
}
});
QuitButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
QuitButton_mousePressed(e);
}
});
jPanel2.setLayout(gridBagLayout5);
SubmitButton.setText("Submit");
SubmitButton.setEnabled(true);
SubmitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
submitButtonActivated();
}
});
SubmitButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent f) {
if (f.getID() == f.MOUSE_PRESSED) {
submitButtonActivated();
}
}
});
jPanel3.setLayout(gridBagLayout4);
jPanel4.setLayout(gridBagLayout3);
contentPane.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(36, 29, 0, 67), 0, 13));
jPanel1.add(jLabelUserName, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(40, 22, 0, 0), 18, 5));
jPanel1.add(jLabelPassword, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(37, 22, 13, 0), 22, 5));
jPanel1.add(jPasswordField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(35, 18, 13, 1), 72, 3));
jPanel1.add(jUserNameField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(40, 17, 0, 1), 119, 2));
contentPane.add(jPanel2, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(26, 61, 34, 67), 0, 5));
jPanel2.add(jPanel3, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 0, 0, 0), 0, 0));
jPanel3.add(SubmitButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(17, 9, 16, 9), 0, 0));
jPanel2.add(jPanel4, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 90, 0, 0), 0, 0));
jPanel4.add(QuitButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(16, 9, 17, 9), 16, 0));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void QuitButton_mousePressed(MouseEvent e) {
ConfirmationsAndNotifications confirm = new ConfirmationsAndNotifications(this, 8);
this.setEnabled(false);
}
void QuitButton_actionPerformed(ActionEvent e) {
ConfirmationsAndNotifications confirm = new ConfirmationsAndNotifications(this, 8);
this.setEnabled(false);
}
void submitButtonActivated() {
try {
//-----------Added to replace deprecated getText() method------------------
jUserNameField.selectAll();
jPasswordField.selectAll();
String userName = jUserNameField.getSelectedText();
String passWord = jPasswordField.getSelectedText();
//---------End Added to replace deprecated getText() method-------------------
if (userName == null | | passWord == null) {
if (userName == null && passWord != null) {
// generate window telling user to supply a username
ConfirmationsAndNotifications notification = new ConfirmationsAndNotifications(x, 90);
} else if (userName != null && passWord == null) {
// generate window telling user to supply a password
ConfirmationsAndNotifications notification = new ConfirmationsAndNotifications(x, 91);
} else {
// generate window telling user to supply both a username
// and a password
ConfirmationsAndNotifications notification = new ConfirmationsAndNotifications(x, 92);
}
}else if (userName.equals("pervigil") && passWord.equals("pervigil")) {
this.hide();
MainFrame f = new MainFrame(this); // create a new MainFrame object
MainFrame currentMainFrame = f;
if (!f.imageFileDoesNotExistOrNotFile) {
f.dispose();
f.setJMenuBar(currentMainFrame.mb); // add the MenuBar object to this instance of MainFrame
this.dispose();
if (f.getConnectionStatus()) {
f.dispose();
} else {
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (com.pervigil.PingUI.packFrame) {
f.pack();
} else {
f.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = f.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
f.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
f.setVisible(true);
}
} else {
this.dispose();
}
} else {
System.exit(1);
} // end of if statment to check username and password fields text
} catch (Exception i) {
System.out.println("NullPointerException or ClassCastException occured during Submitbutton actionPerformed method" + i);
}
} // end of submitButtonActivated method
} // end of LoginFrame class
18 years ago
Hello. I have an actionListener which runs under Windows but when I move the jar file to Solaris the only listener that works is the MouseEventListener.
I need help fast...thanks in advance.
-Jason
18 years ago
I have found that by simply performing a frame.setResizable(false) does not remove maximize and minimize buttons but rather will simply grey them out. I am currently using JDK 1.3.1.
If anyone knows how to completely remove the min, max and close buttons I would be greatful if you sent me an email...jt_rav@yahoo.com
-Jason

Originally posted by deekasha gunwant:
hi babu,
u can remove maximize and minimize button by making the frame non resizable.
frame.setResizable(false);
for close button i've no idea.
regards
deekasha


19 years ago
Hello. If anyone knows how to remove the minimize, maximize and close buttons located in the upper right hand cornder of JFrames please let me know....
19 years ago
I have attempted to install java 1.3.1 and have ran across a light problem. Installation from an rpm works fine but after install is complete if I type java -version, javac, etc I recieve the following message:
/usr/java/jdk1.3.1/bin/i386/native_threads/java: error while loading shared libraries: libstdc++-libc6.1-1.so.2: cannot open shared object file: No such file or directory.
I am stumped. Any suggestions whould be appreciated.
Thanks in advance
-Jason
19 years ago