Derek Duggan

Greenhorn
+ Follow
since Jan 14, 2005
Merit badge: grant badges
For More
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 Derek Duggan

Hey

I'm looking for some help with the below code, As far as i can gather the code for the clip board is correct as i have it working in simple Jframe and it is working right.
I just cant get it to wotk on the code below, i had other methods in the action preformed, but i've taken them out so its easier to read. If any one can see the problem it would be great. The only error that i am getting is for the dimension size, but it jframe runs fine even with that.

Thanks

Derek


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.datatransfer.*;

public class Sending_Mail extends JFrame implements ActionListener, ClipboardOwner
{
private JButton b2;
private JButton b1;
private JTextArea ta1;
private JLabel lb1;
private JTextArea ta2;
private JLabel lb2;
private JTextArea ta3;
private JLabel lb3;
private JTextField t1;
private JLabel lb4;
private JLabel lb5;
private JTextField t2;
private JLabel lb6;
private JTextField t3;
private JComboBox cb1;

/*int rows = 20;
int cols = 30;
textarea = new JTextArea("Initial Text", rows, cols);*/


public String a = "Router A";
public String b = "Router B";
public String a_b = "A-B = 20 \nA-D-B = 30 \nA-C-B = 40 \nA-C-D-B = 50 \nA-D-E-C-B = 60";
public String b_a = "B-A / B-C-A / B-D-A / B-D-E-C-A / B-C-D-E-A";
public int a_b1 = 100;
public int b_a1 = 200;
public int A_B = 100;
public int A_D_B = 300;
public int A_C_B = 250;
public int A_C_D_B = 400;
public int A_D_E_C_B = 500;


public Sending_Mail() {
//construct components
String[] jcomp7Items = {"Ireland", "IP 1", "IP 2", "IP 3", "IP 4", "IP 5", "America", "IP1", "IP2", "IP3"};

b2 = new JButton ("Exit Application");
b1 = new JButton ("Main Menu");
ta1 = new JTextArea (3,10);
lb1 = new JLabel (" All Available Routes");

//Line Wrap
ta2 = new JTextArea ("Some\nInitial\nText", 3, 10);
ta2.setLineWrap(true);

lb2 = new JLabel (" Progress of E-mail");
ta3 = new JTextArea (3,10);
lb3 = new JLabel (" User Information");
t1 = new JTextField (5);
lb4 = new JLabel (" E-mail Size");
lb5 = new JLabel (" Sender Router");
t2 = new JTextField (5);
lb6 = new JLabel (" Destination Router");
t3 = new JTextField (5);

//set components properties
b2.setToolTipText ("Allows the User to exit the Application");
b1.setToolTipText ("Returns the User to the Main Menu");
ta1.setToolTipText ("Shows a List of all Available Routes");
ta2.setToolTipText ("Progress of Routing Algorthnm");
ta3.setToolTipText ("Tells the User whats Going on");
t1.setToolTipText ("Shows the size of the E-Mail Created Earlier");
t3.setToolTipText ("The Destination of the Router");

//adjust size and set layout
setPreferredSize (new Dimension (750, 480));
setLayout (null);

//add components
add (b2);
add (b1);
add (ta1);
add (lb1);
add (ta2);
add (lb2);
add (ta3);
add (lb3);
add (t1);
add (lb4);
add (lb5);
add (t2);
add (lb6);
add (t3);
//add (cb1);

//set component bounds (only needed by Absolute Positioning)

//Exit Application
b2.setBounds (255, 405, 140, 20);

//Main Menu
b1.setBounds (55, 405, 140, 20);
ta1.setBounds (360, 55, 150, 255);
lb1.setBounds (360, 20, 150, 25);
ta2.setBounds (185, 55, 150, 255);
lb2.setBounds (185, 20, 150, 25);
ta3.setBounds (10, 55, 150, 255);
lb3.setBounds (10, 20, 150, 25);
t1.setBounds (535, 55, 100, 25);
lb4.setBounds (530, 20, 95, 25);
lb5.setBounds (530, 100, 130, 25);
t2.setBounds (535, 130, 100, 25);
lb6.setBounds (535, 160, 125, 25);
t3.setBounds (535, 195, 100, 25);
//cb1.setBounds(25,600,95,20);

b1.addActionListener(this);
b2.addActionListener(this);
t3.addActionListener(this);
/*b4.addActionListener(this);
t5.addActionListener(this);*/

}

public void lostOwnership(Clipboard cb, Transferable tr) {};

public void actionPerformed(ActionEvent event)
{

String cliptext = t1.getText();
Toolkit tk = this.getToolkit();
Clipboard cb = tk.getSystemClipboard();
cb.setContents(new StringSelection(cliptext), this);

} // public void actionPerformed()



public static void main (String[] args) {


Sending_Mail application = new Sending_Mail();
application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE );


/*JFrame frame = new JFrame ("Sending_Mail");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new Sending_Mail());
frame.pack();
frame.setVisible (true);*/
}
}
19 years ago
Hey

I'm looking for some help with the below code, As far as i can gather the code for the clip board is correct as i have it working in simple Jframe and it is working right.
I just cant get it to wotk on the code below, i had other methods in the action preformed, but i've taken them out so its easier to read. If any one can see the problem it would be great. The only error that i am getting is for the dimension size, but it jframe runs fine even with that.

Thanks

Derek


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.datatransfer.*;

public class Sending_Mail extends JFrame implements ActionListener, ClipboardOwner
{
private JButton b2;
private JButton b1;
private JTextArea ta1;
private JLabel lb1;
private JTextArea ta2;
private JLabel lb2;
private JTextArea ta3;
private JLabel lb3;
private JTextField t1;
private JLabel lb4;
private JLabel lb5;
private JTextField t2;
private JLabel lb6;
private JTextField t3;
private JComboBox cb1;

/*int rows = 20;
int cols = 30;
textarea = new JTextArea("Initial Text", rows, cols);*/


public String a = "Router A";
public String b = "Router B";
public String a_b = "A-B = 20 \nA-D-B = 30 \nA-C-B = 40 \nA-C-D-B = 50 \nA-D-E-C-B = 60";
public String b_a = "B-A / B-C-A / B-D-A / B-D-E-C-A / B-C-D-E-A";
public int a_b1 = 100;
public int b_a1 = 200;
public int A_B = 100;
public int A_D_B = 300;
public int A_C_B = 250;
public int A_C_D_B = 400;
public int A_D_E_C_B = 500;


public Sending_Mail() {
//construct components
String[] jcomp7Items = {"Ireland", "IP 1", "IP 2", "IP 3", "IP 4", "IP 5", "America", "IP1", "IP2", "IP3"};

b2 = new JButton ("Exit Application");
b1 = new JButton ("Main Menu");
ta1 = new JTextArea (3,10);
lb1 = new JLabel (" All Available Routes");

//Line Wrap
ta2 = new JTextArea ("Some\nInitial\nText", 3, 10);
ta2.setLineWrap(true);

lb2 = new JLabel (" Progress of E-mail");
ta3 = new JTextArea (3,10);
lb3 = new JLabel (" User Information");
t1 = new JTextField (5);
lb4 = new JLabel (" E-mail Size");
lb5 = new JLabel (" Sender Router");
t2 = new JTextField (5);
lb6 = new JLabel (" Destination Router");
t3 = new JTextField (5);

//set components properties
b2.setToolTipText ("Allows the User to exit the Application");
b1.setToolTipText ("Returns the User to the Main Menu");
ta1.setToolTipText ("Shows a List of all Available Routes");
ta2.setToolTipText ("Progress of Routing Algorthnm");
ta3.setToolTipText ("Tells the User whats Going on");
t1.setToolTipText ("Shows the size of the E-Mail Created Earlier");
t3.setToolTipText ("The Destination of the Router");

//adjust size and set layout
setPreferredSize (new Dimension (750, 480));
setLayout (null);

//add components
add (b2);
add (b1);
add (ta1);
add (lb1);
add (ta2);
add (lb2);
add (ta3);
add (lb3);
add (t1);
add (lb4);
add (lb5);
add (t2);
add (lb6);
add (t3);
//add (cb1);

//set component bounds (only needed by Absolute Positioning)

//Exit Application
b2.setBounds (255, 405, 140, 20);

//Main Menu
b1.setBounds (55, 405, 140, 20);
ta1.setBounds (360, 55, 150, 255);
lb1.setBounds (360, 20, 150, 25);
ta2.setBounds (185, 55, 150, 255);
lb2.setBounds (185, 20, 150, 25);
ta3.setBounds (10, 55, 150, 255);
lb3.setBounds (10, 20, 150, 25);
t1.setBounds (535, 55, 100, 25);
lb4.setBounds (530, 20, 95, 25);
lb5.setBounds (530, 100, 130, 25);
t2.setBounds (535, 130, 100, 25);
lb6.setBounds (535, 160, 125, 25);
t3.setBounds (535, 195, 100, 25);
//cb1.setBounds(25,600,95,20);

b1.addActionListener(this);
b2.addActionListener(this);
t3.addActionListener(this);
/*b4.addActionListener(this);
t5.addActionListener(this);*/

}

public void lostOwnership(Clipboard cb, Transferable tr) {};

public void actionPerformed(ActionEvent event)
{

String cliptext = t1.getText();
Toolkit tk = this.getToolkit();
Clipboard cb = tk.getSystemClipboard();
cb.setContents(new StringSelection(cliptext), this);

} // public void actionPerformed()



public static void main (String[] args) {


Sending_Mail application = new Sending_Mail();
application.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE );


/*JFrame frame = new JFrame ("Sending_Mail");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new Sending_Mail());
frame.pack();
frame.setVisible (true);*/
}
}
19 years ago
Hi

Thanks for any help i got with my last problem, an other small problem i have. I'm tring to use a gui to write information to a file, its compling with no errors, creates the file but won't write any thing to it. I have it inside the try and catch no luck i've tried it out side the try and catch also. The same problem

Any help would be great i know its only something small just can't see it

Cheers

Derek

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;

public class Create_Mail extends JPanel implements ActionListener
{
private JButton b1;
private JButton b4;
private JButton b2;
private JButton b3;
private JLabel l4;
private JLabel l5;
private JTextArea ta6;
private JComboBox comb7;
private JTextField t8;
private JTextField t9;
private JButton b10;
private FileOutputStream fos;
private PrintWriter out;

public Create_Mail() {
//construct preComponents
String[] jcomp7Items = {"Ireland", "IP 1", "IP 2", "IP 3", "IP 4", "IP 5", "America", "IP1", "IP2", "IP3"};
//construct components
b1 = new JButton ("Save E-Mail");
b4 = new JButton ("a");
b2 = new JButton ("Exit System");
b3 = new JButton ("Main Menu");
l4 = new JLabel (" To :");
l5 = new JLabel (" Subject :");
ta6 = new JTextArea (5, 5);
comb7 = new JComboBox (jcomp7Items);
t8 = new JTextField (5);
t9 = new JTextField (5);
b10 = new JButton ("Calculate Size of E-Mail");
//adjust size and set layout
setPreferredSize (new Dimension (482, 488));
setLayout (null);
//add components
add (b4);
add (b1);
add (b2);
add (b3);
add (l4);
add (l5);
add (ta6);
add (comb7);
add (t8);
add (t9);
add (b10);
//set component bounds
b1.setBounds (35, 360, 100, 20);
b2.setBounds (160, 395, 105, 20);
b3.setBounds (160, 360, 100, 20);
b4.setBounds (100, 460, 95, 20);
b10.setBounds (285, 360, 180, 20);
l4.setBounds (25, 30, 100, 25);
l5.setBounds (25, 80, 100, 25);
ta6.setBounds (30, 150, 435, 165);
comb7.setBounds (365, 35, 95, 20);
t8.setBounds (135, 85, 210, 20);
t9.setBounds (135, 35, 210, 20);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b10.addActionListener(this);
}

public void actionPerformed( ActionEvent e )
{
//When the user hits the below button a comparsion is made
//If it's true then its executes
//The process is continued depending on the button the user hits

System.out.println("button => "+ e.getActionCommand());

if(( new String("a")).compareTo(e.getActionCommand()) == 0 )
{
System.exit(0);
}

if(( new String("Save E-Mail")).compareTo(e.getActionCommand()) == 0 )
{

try
{

fos = new FileOutputStream("E-mail.txt", true );
out = new PrintWriter(new OutputStreamWriter(fos));

String s1 = ta6.getText();
String s2 = t8.getText();
String s3 = t9.getText();
s1.trim();
s2.trim();
s3.trim();
System.out.println("Test in dos prompt");
out.println(s1 +"," +s2 +"," +s3);
ta6.setText("");
t8.setText("");
t9.setText("");
}
catch (Exception ex){}

}

}
public static void main (String[] args)
{
JFrame frame = new JFrame ("Create_Mail");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
System.out.println("fgfd");
frame.getContentPane().add (new Create_Mail());
frame.pack();
frame.setVisible (true);
}
}
19 years ago
Hey

Small Probelm in the code below i can't get the action listener to work. I've tried using the e.getcommand method on the button also just won't pick up anything for me. Any help with this would be great

Cheers

Derek

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Create_Mail extends JPanel implements ActionListener
{
private JButton jcomp1;
private JButton b1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JTextArea jcomp6;
private JComboBox jcomp7;
private JTextField jcomp8;
private JTextField jcomp9;
private JButton jcomp10;

public Create_Mail() {
//construct preComponents
String[] jcomp7Items = {"Ireland", "IP 1", "IP 2", "IP 3", "IP 4", "IP 5", "America", "IP1", "IP2", "IP3"};

//construct components
jcomp1 = new JButton ("Save E-Mail");
b1 = new JButton ("a");
jcomp2 = new JButton ("Exit System");
jcomp3 = new JButton ("Main Menu");
jcomp4 = new JLabel (" To :");
jcomp5 = new JLabel (" Sublect :");
jcomp6 = new JTextArea (5, 5);
jcomp7 = new JComboBox (jcomp7Items);
jcomp8 = new JTextField (5);
jcomp9 = new JTextField (5);
jcomp10 = new JButton ("Calculate Size of E-Mail");

//adjust size and set layout
setPreferredSize (new Dimension (482, 488));
setLayout (null);

//add components
add (b1);
add (jcomp1);
add (jcomp2);
add (jcomp3);
add (jcomp4);
add (jcomp5);
add (jcomp6);
add (jcomp7);
add (jcomp8);
add (jcomp9);
add (jcomp10);

//set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds (35, 360, 100, 20);
jcomp2.setBounds (160, 395, 105, 20);
jcomp3.setBounds (160, 360, 100, 20);
jcomp4.setBounds (25, 30, 100, 25);
jcomp5.setBounds (25, 80, 100, 25);
jcomp6.setBounds (30, 150, 435, 165);
jcomp7.setBounds (365, 35, 95, 20);
jcomp8.setBounds (135, 85, 210, 20);
jcomp9.setBounds (135, 35, 210, 20);
jcomp10.setBounds (285, 360, 180, 20);
b1.setBounds (100, 460, 95, 20);


}

public void actionPerformed( ActionEvent e )
{

Object Target = e.getSource();

if(Target == b1)
{
//System.out.println("fgfd");
System.exit(0);
}

}

public static void main (String[] args)
{
JFrame frame = new JFrame ("Create_Mail");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
System.out.println("fgfd");
frame.getContentPane().add (new Create_Mail());
frame.pack();
frame.setVisible (true);
}

}
19 years ago
Hey

Hoping for a little bit of help, i've a gui designed which takes in information from the user and saves it to a .txt file. Is it possible to measure the actual length of that file and return a value to the user in bytes, and if it is how could i get it to work

Thanks for any Help

Derek
19 years ago