• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Clip Board Problem

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);*/
}
}
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Derek Duggan:
I just cant get it to wotk on the code below ...



What isn't working? Are you getting an exception? A compilation error? Are you getting the wrong layout? The wrong output? A bit more information would help us help you.
reply
    Bookmark Topic Watch Topic
  • New Topic