JFrame - MouseEvent handling, 2nd

Hi,
the following code has a JFrame, which opens via the JButton a second JFrame, which holds a JTable:
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class FrameTester {
     private void createAndShowGUI() {
          // Create and set up the window.
          JFrame frame = new JFrame("This is a Frame.");
          // Show the frame
          int width = 300;
          int height = 300;
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(width, height);
          frame.getContentPane().setLayout(new GridLayout(3, 3));
          frame.addMouseListener(new MouseListener() {
               public void mouseClicked(MouseEvent e) {
                    System.out.println("Frame clicked.");
               public void mousePressed(MouseEvent e) {
               public void mouseReleased(MouseEvent e) {
               public void mouseEntered(MouseEvent e) {
               public void mouseExited(MouseEvent e) {
          JButton b1 = new JButton("OK");
          b1.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                    new FrameTable();
          JLabel jL1 = new JLabel();
          JLabel jL2 = new JLabel();
          JLabel jL3 = new JLabel();
          JLabel jL4 = new JLabel();
          JLabel jL5 = new JLabel();
          JLabel jL6 = new JLabel();
          JLabel jL7 = new JLabel();
          JLabel jL8 = new JLabel();
          frame.getContentPane().add(jL1);
          frame.getContentPane().add(jL2);
          frame.getContentPane().add(jL3);
          frame.getContentPane().add(jL4);
          frame.getContentPane().add(b1);
          frame.getContentPane().add(jL5);
          frame.getContentPane().add(jL6);
          frame.getContentPane().add(jL7);
          frame.getContentPane().add(jL8);
          // Display the window.
          frame.setVisible(true);
      * @param args
     public static void main(String[] args) {
          // TODO Auto-generated method stub
          FrameTester ft = new FrameTester();
          ft.createAndShowGUI();
} import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTable;
public class FrameTable {
     FrameTable() {
          // Create and set up the window.
          JFrame frame = new JFrame("This frame has a JTable.");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setLayout(new GridLayout(2, 1));
          String[] columnNames = { "First Name", "Last Name", "Id" };
          Object[][] data = { { "Mary", "Campione", new Integer(5) },
                    { "Alison", "Huml", new Integer(3) } };
          JTable table = new JTable(data, columnNames);
          JLabel jL1 = new JLabel();
          frame.getContentPane().add(jL1);
          frame.getContentPane().add(table);
          // Display the window.
          frame.pack();
          frame.setVisible(true);
}First of all, I'm wondering why the first frame closes as well, if the second one is closed by the support button for closing?
But now my main questions:
The second JFrame has a JTable. When I edit a cell, for example the ID cell (3rd column) of the first row, and hit the enter key or click inside another cell of the JTable, the current value of the edited cell is stored automatically by the JTable. But if I edit a cell and click somewhere outside the cell, for example
1. Above the cell (where in this example a JLable is placed)
2. Close the second JFrame by clicking the support button for closing
3. Click inside the first JFrame
I would like that the current edited cell stores the current value as well. How to achieve this?
Thx!

but I thought, that each instance of a JFrame is closed independently...It is if you choose the appropriate close operation. So again I ask why did you choose "exit" instead of one of the other options? Did you read the API to understand what all the options mean?
but no change in behavior. I found some posts that this worked for other code samples, but why not here? Then no focus lost event was generated. If you click on a label it doesn't gain focus so focus is still on the editor. If you click on a panel of the frame a panel doesn't gain focus either. So I'm not sure what you expect to happen but I guess you need to use the second approach of manually stopping cell editing when you click on another component.
If you click on the close button, the same problem is that the table doesn't lose focus. So I guess you need to add a WindowListener to the frame and manually stop editing in the windowClosing() method. You can check out my "Closing an Application" entry from the above blog.

Similar Messages

  • Dual mon  jframe minimizes on 2nd when click on 1st

    Hi, i am kinda new to java. This is what i try to do : display a jpg image full screen on the 2nd monitor. It seemed ok at first, but when i did a mouse click on the 1st monitor, the full screen on the 2nd got minizied. Code attached, pls help. thanks.
    import java.awt.*;
    import javax.swing.*;
    class Test3
        void doDisplay()
            GraphicsEnvironment ge  = GraphicsEnvironment.getLocalGraphicsEnvironment();    
            GraphicsDevice[] gdlist = ge.getScreenDevices();    
            GraphicsDevice gd = gdlist[gdlist.length-1];
            GraphicsConfiguration gc = gdlist[gdlist.length-1].getDefaultConfiguration();
            JFrame frame = new JFrame("Frame");
            frame.setResizable(false);
            frame.setUndecorated(true);
            frame.setExtendedState(frame.getExtendedState() & ~frame.ICONIFIED);
            gd.setFullScreenWindow(frame);
            ImageIcon img = new ImageIcon("foo.jpg");
            Graphics2D g2 = (Graphics2D)frame.getGraphics();
            Dimension d = frame.getSize();
            g2.drawImage(img.getImage(), 0, 0, d.width, d.height, null);
            frame.setVisible(true);
            public static void main (String a[])
                    Test3 test = new Test3();
                    test.doDisplay();
    }

    what value is this statement?frame.getExtendedState() & ~frame.ICONIFIEDOne thing you can try is to ignore the mouse clicks using a GlassPane...
    protected class GlassPane extends JPanel implements MouseListener, MouseMotionListener {
      public void mouseDragged(MouseEvent e) {}
      public void mouseMoved(MouseEvent e) {}
      public void mouseClicked(MouseEvent e) {}
      public void mouseEntered(MouseEvent e) {}
      public void mouseExited(MouseEvent e) {}
      public void mousePressed(MouseEvent e) {}
      public void mouseReleased(MouseEvent e) {}
    // example of usage...
    GlassPane glassPane = new GlassPane();
    frame.setGlassPane(glassPane);
    glassPane.setVisible(true);

  • How does Mavericks handle 2nd monitor differently?

    Since I upgraded to Mavericks, I have liked having a 2nd task bar on my 2nd monitor.
    But I haven't figured out how it decides where to put pop up windows.    Sometimes they are on one monitor, other times on the other.   How does it decide?
    And I have one application (SimpleFloatingClock) that used to start up on my 2nd monitor when I reboot, but now starts off on the 1st monitor (where it would boot up when I have to reboot without my 2nd monitor - which in the past has been at the Genius Bar).

    I like to have my iTunes on one monitor, but use my iMac's display for other work.   But when the iMac's display is active, I get a window from my iTunes behind my browser (or whatever) that I'm using on my iMac.    I liked it the old way when it popped up in front of my iTunes and could see it.

  • Using JPanel with JFrame

    I am using a JFrame to encapsulate my program. I want to have a JPanel inside my JFrame to handle all of my 2d displaying (like fillRect() etc...). I used forte to set this up but I am having problems dispaying on the JPanel. Here is my code:
    here is how I call the function from the main .java file
    I dubuged this and know it works (proof will come later)
    private void Start_ButtonActionPerformed(java.awt.event.ActionEvent evt)
    myDisplay.draw();
    here is my entire JPanel class
    import java.awt.*;
    import javax.swing.*;
    public class Display extends javax.swing.JPanel
    public Display() {
    initComponents();
    public void paintComponent(Graphics g )
    System.out.println("1");
    super.paintComponent(g);
    g.setColor(Color.black);
    g.fillOval(50,10,60,60);
    public void draw()
    System.out.println("1");
    this.repaint(); //i also tried repaint() but it didn't work either
    System.out.println("2");
    private void initComponents()
    setLayout(new java.awt.BorderLayout());
    when I press the start button, 1 and 2 are displayed but 3 isn't. For some reason the repaint() function is not telling the paintComponent function to work. Any help is appreciated.
    Thanks,
    Every_man

    Every_man,
    After doing the super.paintComponent(g); you must use Graphics2D. So you next line should cast your graphics object to a graphics 2D object, like this. Graphics2D g2 = (Graphics2D)g;

  • Key Handler

    //My source code:
    package keyhandler;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.util.Collections;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Set;
    import javax.swing.JFrame;
    public class Handler implements KeyListener {
    private boolean FINISH = true;
    private Set<Integer> set;
    *@param args*
    public Handler() {
    set = Collections.synchronizedSet(new HashSet<Integer>());
    public void handle() {
    while (FINISH) {
    synchronized (set) {
    Iterator<Integer> i = set.iterator();
    String k= "";
    while (i.hasNext()) {
    int key = i.next();
    switch (key) {
    case 27: FINISH=false;break;
    case 38:k = k.concat(" Up");break;
    case 39:k = k.concat(" right");break;
    case 40:k = k.concat(" down");break;
    case 37:k = k.concat(" left");break;
    default :k = k.concat(" "+key);break;
    System.out.println(k);
    System.exit(0);
    public static void main(String[] args) {
    Handler handler = new Handler();
    JFrame frame = new JFrame();
    frame.setVisible(true);
    frame.addKeyListener(handler);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    handler.handle();
    @Override
    public void keyPressed(KeyEvent arg0) {
    synchronized (set) {
    set.add(arg0.getKeyCode());
    @Override
    public void keyReleased(KeyEvent arg0) {
    synchronized (set) {
    set.remove(arg0.getKeyCode());
    @Override
    public void keyTyped(KeyEvent arg0) {
    // TODO Auto-generated method stub
    // I 've got this code to handle keys. I am making an interface for a game and I would like to handle more than one key at same time. I want to handle the arrow keys. It seems to be fine except when I am holding down the Up arrow key i can hold just another key at same time.
    Example :
    Down Left Right - holding down left and right arrow key at same time
    Up left - with up arrow key i can hold just another one key. Not more.
    Can anybody help me to sort out this source?

    Thanks for your idea, very cool very useful
    [fresh fridays |http://reggae-cd.net/fresh-fridays-reggae-dance-in-jamaica]
    [passa passa DVD |http://reggae-dvd.com/passa-passa-reggae-music-and-dancing]
    [passa passa  |http://bestreggaemusic.com/passa-passa-90-mavado-fall-rain-fall-official-dance]
    [reggae videos|http://reggae-dancehall.net/crabb-up-friday-dancehall-reggae]

  • Dispose when jframe is minimised

    hey peepz...
    i want the jframe to be disposed instead of minimised when another jframe appears. i am not sure how to do it because the latter jframe or the 2nd jframe belongs to the same class but is created by different constructor. so it is something like constructor2 is being called upon when something is done in constructor1.
    how do we go around doing that?
    thanks
    farah k.

    public class whatever1 extends jpanel {
    whatever2 panel1;
    whatever3 panel2;
    whatever1 (String variable1, String variable 2) {
    whatever2 panel1 = new whatever2(variable1, panel2);
    whatever3 panel2 = new whatever3( variable2, panel1);
    add (jpanel1);
    add (jpanel2);
    whatever1 (String variable1, String variable 2, String variable3) {
    whatever2 panel1 = new whatever2(variable3, panel2);
    whatever3 panel2 = new whatever3( test, panel1);
    add (jpanel1);
    add (jpanel2);
    class whatever2 extends jpanel {
    JButton action1;
    String variable1, variable3, variable4;
    jpanel(String name, whatever3 jpanel2) {
    action1.addActionListener(
    public void actionPerformed(ActionEvent e) {
         dispose(); /*i want to dispose this the first frame which was generated by the first constructor but there is no such function within jpanel*/
    new whatever1(variable1, variable3, variable4);
    }

  • I am having horrible problems getting some examples to work

    I am trying to get a couple examples to work from out of Java Examples in a Nutshell, but they are programmed oddly and will not work. I am using a windows 2000 platform with JDK 1.3.1 installed and working properly.
    I have so far typed in these 2 examples:
    import javax.swing.*;
    import java.awt.*;
    public class Containers extends JPanel
    { public Containers()
    { this.setBackground(Color.white);
    this.setFont(new Font("Dialog", Font.BOLD,24));
    JPanel p1 = new JPanel();
    p1.setBackground(new Color(200, 200, 200)); // Panel1 is darker
    this.add(p1); //p1 is contained by this component
    p1.add(new JButton("#1")); //Button 1 is contained in p1
    JPanel p2 = new JPanel();
    p2.setBackground(new Color(150,150,150)); // p2 is darker than p1
    p1.add(p2); // p2 is contained in p1
    p2.add(new JButton("#2")); // button 2 is contained in p2
    JPanel p3 = new JPanel();
    p3.setBackground(new Color(100,100,100));
    p2.add(p3); // p3 is contained in p2
    p3.add(new JButton("#3")); // button 3 is contained in p3
    JPanel p4 = new JPanel();
    p4.setBackground(new Color(150,150,150));
    p1.add(p4);
    p4.add(new JButton("#4")); //button 4 is contained in p4
    p4.add(new JButton("#5")); //Button 5 is also contained in p4
    this.add(new JButton("#6")); // button 6 is contained in this component
    And this program
    //ShowComponent.java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.beans.*;
    import java.lang.reflect.*;
    import java.util.Vector;
    public class ShowComponent extends JPanel
    public static void main(String[] args)
    {  // process the command line to get the compenents to display
    Vector components = getComponentsFromArgs(args);
    // Create a frame (Window) to display the components to display
    JFrame frame = new JFrame("ShowComponent");
    // Handle window close requests by exiting the VM
    frame.addWindowListener(new WindowAdapter() { //anonymous inner class
    public void WindowClosing(WindowEvent e) { System.exit(0); }
    // set up a menu system that allows the user to select the Look And Feel
    // of the component from a list of installed PLAF's
    JMenuBar menubar = new JMenuBar(); // create a menu bar
    frame.setJMenuBar(menubar); // tell the frame to display the menubar
    JMenu plafmenu = createPlafMenu(frame); // create a menu
    menubar.add(plafmenu); // Add the menu to the menubar
    // Create a JTabbedPane to display each of the components
    JTabbedPane pane = new JTabbedPane();
    // Now add each component as a tab of the tabbed pane
    // use the unqualified component classname as the tab text
    for(int i = 0; i < components.size(); i++)
    { Component c = (Component)components.elementAt(i);
    String classname = c.getClass().getName();
    String tabname = classname.substring(classname.lastIndexOf('.')+1);
    pane.addTab(tabname,c);
    // Add the tabbedpane to the frame. Note: the call to getContentPane()
    // This is required for JFrame, but not for most swing components
    frame.getContentPane().add(pane);
    // Set the frame size and pop it up
    frame.pack(); //Make the frame as big as its children need
    frame.setVisible(true); // Make the frame visible on the screen
    // The main() method exits now but the Java VM keeps running because
    // all AWT programs automatically start an event-handling thread.
    //** this static method queries the system to find out what **
    //** Pluggable LookAndFeel (PLAF) implementations are available **
    //** then it creates a JMenu component that lists each of the **
    //** implementations by name and allows the user to select one **
    //** of them using JRadioButtonMenuItem components. When the **
    //** user selects one, the selected menu item traverses the **
    //** component hierarchy and tells all components to use the new**
    //** PLAF. **
    public static JMenu createPlafMenu(final JFrame frame)
    { //Creates the menu
    JMenu plafmenu = new JMenu("Look and Feel");
    // Create an object used for radio button mutual exclusion
    ButtonGroup radiogroup = new ButtonGroup();
    //Look up the available look and feels
    UIManager.LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
    //Loop through the plafs, add a menu item for each one
    for(int i = 0; i < plafs.length; i++)
    { String plafName = plafs[i].getName();
    final String plafClassName = plafs.getClassName();
    // Create the menu items
    JMenuItem item = plafmenu.add(new JRadioButtonMenuItem(plafName));
    // tell the menu item what to do when it is selected
    item.addActionListener(new ActionListener()
    { public void actionPerformed(ActionEvent e)
    { try
    { // Set the new Look And Feel
    UIManager.setLookAndFeel(plafClassName);
    // tell each component to change its look and feel
    SwingUtilities.updateComponentTreeUI(frame);
    //tell the frame to resize itsself to its childrens
    // new desired services
    frame.pack();
    catch(Exception ex) {System.err.println(ex);
    // Only allow one menu item to be selected at once
    radiogroup.add(item);
    return plafmenu;
    //** this method loops through the command line arguements looking for **
    //** class names of components to create and property settings for those**
    //** components in the form name=value. this method demonstrates **
    //** reflection and JavaBeans introspection as they can be aplied to **
    //** dynamically created GUI's **
    public static Vector getComponentsFromArgs(String[] args)
    { Vector components = new Vector();  // List of Components to return
    Component component = null; // the current component
    PropertyDescriptor[] properties = null; // Properties of the component
    Object[] methodArgs = new Object[1]; // we'll use this below
    nextarg: // this is a labeled loop
    for (int i = 0; i < args.length; i++)
    { // loop through all the arguments
    // if the argument does not contain an equal sign, then
    // it is a component class name. Otherwise it is a
    // property setting
    int equalsPos = args[i].indexOf('=');
    if (equalsPos == -1)
    { // Its the name of a component
    try { //Load the named component class
    Class componentClass = Class.forName(args[i]);
    //Instantiate it to create the component instance
    component = ((Component)componentClass.newInstance());
    //Use Java beans to introspect the component
    //And get the list of properties it supports
    BeanInfo componentBeanInfo = Introspector.getBeanInfo(componentClass);
    properties = componentBeanInfo.getPropertyDescriptors();
    catch (Exception e)
    { // If an step failed, print an error and exit
    System.out.println("Can't load, instantiate, " +
    "or introspect: " +args[i]);
    System.exit(1);
    //If we succeeded, store the component in the vector
    components.addElement(component);
    else { // the arg is a name=value property specification
    String name = args[i].substring(0, equalsPos); //property name
    String value = args[i].substring(equalsPos+1); //property value
    // If we do not hava component to set this proerty on, skip!
    if (component == null) continue nextarg;
    // Now look through the properties descriptors for this
    // Component to find one with the same name
    for(int p = 0; p < properties.length; p++)
    { if (properties[p].getName().equals(name))
    { // okay, we found a property of the right name
    // now to get its type, and the setter method
    Class type = properties[p].getPropertyType();
    Method setter = properties[p].getWriteMethod();
    //check if property is read- only !
    if (setter == null)
    { System.err.println("Property " + name+ "is read-only");
    continue nextarg; // continue with the next arguement
    // try to convert the property value to the right type
    // we support a small set of common property types here
    // Store the converted value in an object[] so it can
    //be easily passed when we invoke the property setter
    try { if (type == String.class)
    { // no conversion needed
    methodArgs[0] = value;
    else if (type == int.class)
    { // String to int
    methodArgs[0] = Integer.valueOf(value);
    else if (type == boolean.class)
    { //to boolean
    methodArgs[0] = Boolean.valueOf(value);
    else if (type == Color.class)
    { // to Color
    methodArgs[0] = Color.decode(value);
    else if (type == Font.class)
    { // String to Font
    methodArgs[0] = Font.decode(value);
    else { // if we cannotconvert, ignore the proprty
    System.err.println("Property " + name+ " is of unsupported type "
    + type.getName());
    continue nextarg;
    catch (Exception e)
    { System.err.println("Can't set Property: " + name);
    // NOw go to next command-line arg
    continue nextarg;
    // If we get here we didn't find the named property
    System.err.println("Warning: No such property: " + name);
    return components;
    //** A component subclass that demonstrates nested containers and components.
    //** It creates the hierarchy shown below, and uses different colors to
    //** distinguish the different nesting levels of the containers
    //** containers---panel1----button1
    //** | |---panel2----button2
    //** | | |----panel3----button3
    //** | |------panel40---button4
    //** | |---button5
    //** |---button6
    They both compile fine but when I go to run them together I get an error. the command given in the book to run them both together is:
    java ShowComponent\Containers
    But it does not work. I also tried to append Containers to the bottom of ShowComponent and I got an error that said public class Containers extends JPanel needs to have its own file called Containers.java . . I do not understand that as the file was named correctly for ShowComponent.java. I need to knw either what the true command is for running the programs together or what to name container.java that will make it run inside of ShowContainer.java
    this is very frustrating as I need to know these answers for work and no one here in the IT department knows how to program in Java but me

    Hi,
    I tried the example and got some weird error messages as follows:
    ********* error messages*********
    ShowComponent.java:90: cannot resolve symbol
    symbol : method getName ()
    location: class javax.swing.UIManager.LookAndFeelInfo[]
    { String plafName = plafs.getName();
    ^
    ShowComponent.java:91: cannot resolve symbol
    symbol : method getClassName ()
    location: class javax.swing.UIManager.LookAndFeelInfo[]
    final String plafClassName = plafs.getClassName();
    ^
    ShowComponent.java:139: cannot resolve symbol
    symbol : method indexOf (char)
    location: class java.lang.String[]
    int equalsPos = args.indexOf('=');
    ^
    ShowComponent.java:143: cannot resolve symbol
    symbol : method forName (java.lang.String[])
    location: class java.lang.Class
    Class componentClass = Class.forName(args);
    ^
    ShowComponent.java:161: cannot resolve symbol
    symbol : method substring (int,int)
    location: class java.lang.String[]
    String name = args.substring(0, equalsPos); //property name
    ^
    ShowComponent.java:162: cannot resolve symbol
    symbol : method substring (int)
    location: class java.lang.String[]
    String value = args.substring(equalsPos+1); //property value
    ^
    6 errors.
    *****end of error messages*****
    I use jdk1.3 and Win2000. Can anybody tell me how to delete above error messages?
    Thanks a lot.
    Li

  • Problem talking from a PDF-embedded 3D model to a Web page

    I am having serious problems in my attempts to talk from a PDF-embedded 3D model to a JavaScript function in an outer HTML page. Im am using the latest acroreader on Windows for display.
    The HTML page has a properly set up messageHandler on the with the PDF, as per Adobe documentation. Also, the document is disclosed.
    Within the 3D model script, I am trying to use the
    host.hostContainer.postMessage()
    function to report to the outside world on item distances and angles that were selected and logged in a mouseEvent handler. I have verified that "host" really refers to the PDF document, and that hostContainer and postMessage exist.
    Nevertheless, when I call the postMessage() function, I am seeing weird error messages on the Acrobat JavaScript console, nothing arrives in the HTML page functions, and ultimately the browser and acroreader both die independent deaths.
    My suspicion is that this is somehow related to having different JS interpreters for the model and the document. I found documentation on how to access the model interpreter from the document, but not the other way around.
    Can anybody give me some hints on the right approach to channel data from an event handler in a 3D model embedded in a PDF to an HTML page JavaScript function?

    Dear Seabor,
    dissect
    http://www.pdf3d.co.uk/pdf/HyperlinkExample.pdf
    with your favorite tool (pdftk and vim work for me)
    and see how document-level and model-level JavaScript
    interact to achieve the results.
            Sincerely, Michail

  • Class, interface, or emun expected.

    When I compile to code I get 60 "class, interface, or emun expected errors. I know that this error usual means that there is a bracket out of place or missing. I went through and add line comments that link the opening and closing brackets together. Can anyone take a look and let me know what I am missing. Thanks.
    {code}
    // Inventory4.java
    // Program will track total inventory items in stock.
    import java.io.*;
    import javax.swing.JFrame;
    public class Inventory4
    {//1
    public class Item
    {//2
    private double unitPrice;
    private double quantityStock;
    private double inventoryValue;
    private double totalInventory;
    private int itemNumber;
    private String itemName;
    /** Create a new instance of Item Name */
    public Item(double UnitPrice,double QuantityStock,int      ItemNumber,String ItemName)
    {//3
    itemName = ItemName;
    itemNumber = itemNumber;
    unitPrice = UnitPrice;
    quantityStock = QuantityStock;
    }//3
    public void setItemName(String ItemName)
    {//4
    itemName = ItemName;
    }//4
    public void setItemNumber(int ItemNumber)
    {//5
    itemNumber = ItemNumber;
    }//5
    public void setUnitPrice(String InventoryHardware)
    {//6
    inventoryHardware=InventoryHardware;
    }//6
    public void setUnitPrice(double UnitPrice)
    {//7
    unitPrice = UnitPrice;
    }//7
    public void setQuantityStock(double QuantityStock)
    {//8
    quantityStock = QuantityStock;
    }//8
    public String getItemName()
    {//9
    return itemName;
    }//9
    public int getItemNumber()
    {//10
    return itemNumber;
    }//10
                        public String getInvetoryHardware()
    {//11
                        return inventoryHardware;
    }//11
    public double getUnitPrice()
    {//12
    return unitPrice;
    }//12
    public double getQuantityStock()
    {//13
    return quantityStock;
    }//13
    public String getInventoryHardware()
    {//14
    return inventoryHardware;
    }//14
    public double computeinventoryValue()
    {//15
    return quantityStock * unitPrice;
    }//15
    public double computetotalInventory()
    {//16
    return totalInventory = totalInventory + inventoryValue;
    }//16
    public String toString()
    {//17
    return (itemName);
    }//17
    }//2
    }//1
    // SubItem.java
    // Sub class to main program
    public class SubItem extends Item
    {//18
    private String inventoryHardware;
    private double restockingFee = .05;
    public SubItem(double UnitPrice,double QuantityStock,int InventoryWriteoffs,int
    ItemNumber,String ItemName)
    {//19
    setUnitPrice(UnitPrice);
    setQuantityStock(QuantityStock);
    setItemNumber(ItemNumber);
    setItemName(ItemName);
    inventoryWriteoffs = InventoryWriteoffs;
    }//19
    public void setInventoryHardware(String InventoryHardware)
    {//20
    inventoryHardware = InventoryHardware;
    }//20
    public int getInventoryHardware()
    {//21
    return inventoryWriteoffs;
    }//21
    public double computeRestockingFee()
    {//22
    return ((getUnitPrice() * getQuantityStock()) * restockingFee);
    }//22
    }//18
    private static BufferedReader stdin = new BufferedReader( new InputStreamReader(      System.in ) );
    private static int totalCount = 5;
    public Inventory4()
    {//23
    double unitPrice; // Unit price of each item
    double quantityStock; // Number of items in stock
    double inventoryValue; // Place holder for calculated inventory value
    double totalInventory; // Place holder for calculated total inventory value
    int itemNumber; // Item Number
    String itemName = ""; // Name of each item
    }//23
    public static void main(String[] args)throws IOException
    {//24
    SubItem myItem[];
    myItem = new SubItem[5];
    myItem[0] = new SubItem(10.35,20,4,1,"Traxx");
    myItem[1] = new SubItem(176.34,10,5,2,"Panels");
    myItem[2] = new SubItem(85.34,4,4,3,"Surfaces");
    myItem[3] = new SubItem(1.95,56,6,4,"Brackets");
    myItem[4] = new SubItem(82.34,8,1,5,"Overheads");
    printArray(myItem);
    myItem = sortArray(myItem);
    System.out.println(" Inventory List Sorted by Items \n\n");
    printArray(myItem);
    ItemButton itemButton = new ItemButton(myItem,totalCount); // Make ItemButton
    itemButton.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    itemButton.setSize( 350,390 ); // Window size
    itemButton.setVisible( true ); // display window
    } //24 End Main Method
    private static SubItem[] printArray(SubItem[] myItem)
    {//25
    double totalInventory = 0;
    double restockingFee = 0;
    for (int i = 0; i<5;++i)
    {//26
    System.out.println("\n The Item Number is " + i + myItem.getItemNumber() );
    System.out.println("\n Item Name is " + myItem.getItemName() );
    System.out.println("\n Quantity in Stock is " + myItem.getQuantityStock() );
    System.out.println("\n Inventory Write-off is " +      myItem.getInventoryWriteoffs() );
    System.out.println("\n Inventory Value is $" + myItem.computeinventoryValue               ());
    totalInventory = totalInventory + myItem.computeinventoryValue();
    restockingFee = totalInventory + myItem.computeRestockingFee();
    } //26 End For Loop
    System.out.println("\n Total Value of all inventory is " + totalInventory);
    System.out.println("\n Total Value of all inventory with restock fee $" +      restockingFee);
    return myItem;
    }//25
    private static SubItem[] sortArray(SubItem[] myItem)
    {//27
    SubItem temp = new SubItem();
    int i, j;
    int array_size = 5;
    for (i = (array_size - 1); i >= 0; i--)
    {//28
    for (j = 1; j <= i; j++)
    {//29
    if (myItem[j-1].getItemName().compareTo(myItem[j].getItemName()) > 1)
    {//30
    temp = myItem[j-1];
    myItem[j-1] = myItem[j];
    myItem[j] = temp;
    } //30 End if
    } //29 End inner for loop
    } //28 End outer for loop
    return myItem;
    } //27 End Method
    // ItemButton.java
    // This will create GUI buttons.
    // Display the Items.
    import java.awt.FlowLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JOptionPane;
    import javax.swing.SwingConstants;
    public class ItemButton extends JFrame
    {//31
    private JButton nextJButton; // text button
    private JButton prevJButton; // icon button
    private JLabel lblItemName; // text field with set size
    private JTextField txtItemName; // text field constructed with text
    private JTextField textField3; // text field with text and size
    private JLabel lblItemNumber; // text field with set size
    private JTextField txtItemNumber; // text field constructed with text
    private JLabel lblUnitPrice; // text field with set size
    private JTextField txtUnitPrice; // text field constructed with text
    private JLabel lblQuantityStock; // text field with set size
    private JTextField txtQuantityStock; // text field constructed with text
    private JLabel lblInventoryWriteoffs; // text field with set size
    private JTextField txtInventoryWriteoffs; // text field constructed with text
    private JLabel lblcomputeRestockingFee; // text field with set size
    private JTextField txtcomputeRestockingFee; // text field constructed with text
    private JLabel lblcomputeinventoryValue; // text field with set size
    private JTextField txtcomputeinventoryValue; // text field constructed with text
    private JLabel lblcomputetotalInventory; // text field with set size
    private JTextField txtcomputetotalInventory; // text field constructed with text
    SubItem[] arraySubItem;
    private int currentArrayCounter;
    private int arrayCount;
    public ItemButton(SubItem[] myItem, int totalArrayCount)
    {//32
    super ( "Inventory" );
    arraySubItem = myItem;
    arrayCount = totalArrayCount;
    currentArrayCounter = 0;
    setLayout( new FlowLayout() ); // set frame layout
    Icon iconNext = new ImageIcon( getClass().getResource( "" ) );
    Icon iconPrev = new ImageIcon( getClass().getResource( "" ) );
    lblItemName = new JLabel( "Item Name ");
    add( lblItemName ); // textField3 to JFrame
    txtItemName = new JTextField( "", 15 );
    add( txtItemName ); // add textField3 to JFrame
    lblItemNumber = new JLabel( "Item Number ");
    add( lblItemNumber ); // textField3 to JFrame
    txtItemNumber = new JTextField( "", 15 );
    add( txtItemNumber ); // add textField3 to JFrame
    lblUnitPrice = new JLabel( "Unit Price ");
    add( lblUnitPrice ); // textField3 to JFrame
    txtUnitPrice = new JTextField( "", 15 );
    add( txtUnitPrice ); // add textField3 to JFrame
    lblQuantityStock = new JLabel( "Quantity Stock " );
    add( lblQuantityStock ); // textField3 to JFrame
    txtQuantityStock = new JTextField( "", 15 );
    add( txtQuantityStock ); // add textField3 to JFrame
    lblInventoryHardware = new JLabel( "Inventory Hardware " );
    add( lblInventoryHardware ); // textField3 to JFrame
              txtInventoryHardware = new JTextField( "", 15 );
    add( txtInventoryHardware ); // add textField3 to JFrame
    lblcomputeRestockingFee = new JLabel( "Restocking Fee ");
    add( lblcomputeRestockingFee ); // textField3 to JFrame
    txtcomputeRestockingFee = new JTextField( "", 15 );
    add( txtcomputeRestockingFee ); // add textField3 to JFrame
    lblcomputeinventoryValue = new JLabel( "Inventory Value " );
    add( lblcomputeinventoryValue ); // textField3 to JFrame
    txtcomputeinventoryValue = new JTextField( "", 15 );
    add( txtcomputeinventoryValue ); // add textField3 to JFrame
    lblcomputetotalInventory = new JLabel( "Total Inventory ");
    add( lblcomputetotalInventory ); // textField3 to JFrame
    txtcomputetotalInventory = new JTextField( "", 15 );
    add( txtcomputetotalInventory ); // add textField3 to JFrame
                   nextJButton = new JButton( "Next" ); // button with Next
                   prevJButton = new JButton( "Previous"); // button with Prev
                   add(prevJButton);
                   add(nextJButton); // add plainJButton to JFrame
                   ButtonHandler handler = new ButtonHandler();
    nextJButton.addActionListener( handler );
    prevJButton.addActionListener( handler );
    setTextFields();
    } //32 End ButtonFrame constructor
    private class ButtonHandler implements ActionListener
    {//33
    public void actionPerformed( ActionEvent event )
    {//34
    if (event.getActionCommand()== "prevJButton")
    {//35
    currentArrayCounter++;
    }//35
    else
    {//36
    currentArrayCounter++;
    }//36
    setTextFields();
    } //34 End Method ActionPerformed
    } //33 End Private inner class ButtonHandler
    private void setTextFields()
    {//37
    if (currentArrayCounter == arrayCount)
    {//38
    currentArrayCounter = 0;
    }//38
    if (currentArrayCounter < 0)
    {//39
    currentArrayCounter = arrayCount;
    }//39
    txtItemName.setText(arraySubItem[currentArrayCounter].getItemName());
    txtItemNumber.setText(arraySubItem[currentArrayCounter].getItemNumber()      +"");
    txtUnitPrice.setText(arraySubItem[currentArrayCounter].getUnitPrice()+"");
    txtQuantityStock.setText(arraySubItem[currentArrayCounter].getQuantityStock      ()+"");
    txtInventoryWriteoffs.setText(arraySubItem      [currentArrayCounter].getInventoryWriteoffs()+"");
    txtcomputeRestockingFee.setText(arraySubItem      [currentArrayCounter].computeRestockingFee()+"");
    txtcomputeinventoryValue.setText(arraySubItem     [currentArrayCounter].computeinventoryValue()+"");
    txtcomputetotalInventory.setText(arraySubItem      [currentArrayCounter].computetotalInventory()+"");
    }//37
    } //31 End class ItemButton
    {code}

    I have eliminated most of the problems, but I am still getting 11 Class interface or emun errors.
    It says the first error is in the lines that import the GUI buttons
    // Inventory4.java
    // Program will track total inventory items in stock.
    import java.io.*;
    import javax.swing.JFrame;
    public class Inventory4
    {//1
       public static void main (String [] args)  ;
         {//40
           class Item
           {//2
             private double unitPrice;
             private double quantityStock;
             private double inventoryValue;
             private double totalInventory;
             private int itemNumber;
             private String itemName;
                          /** Create a new instance of Item Name */
                       public Item(double UnitPrice,double QuantityStock,int                                                
                                  ItemNumber,String ItemName)
                                              {//3
                                                 itemName = ItemName;
                                                 itemNumber = itemNumber;
                                                 unitPrice = UnitPrice;
                                                quantityStock = QuantityStock;
                                                }//3
                                                           public void setItemName(String ItemName)
                                                          {//4
                                                        itemName = ItemName;
                                                            }//4
                                                           public void setItemNumber(int ItemNumber)
                                                            {//5
                                                       itemNumber = ItemNumber;
                                                             }//5
                                                          public void setUnitPrice(String InventoryHardware)
                                                                   {//6
                                                                 inventoryHardware=InventoryHardware;
                                                                    }//6
                                                          public void setUnitPrice(double UnitPrice)
                                                                    {//7
                                                      unitPrice = UnitPrice;
                                                                     }//7
                                                          public void setQuantityStock(double QuantityStock)
                                                                           {//8
                                                     quantityStock = QuantityStock;
                                                                             }//8
                                                          public String getItemName()
                                                                             {//9
                                                      return itemName;
                                                                                     }//9
                                                          public int getItemNumber()
                                                                                     {//10
                                                      return itemNumber;
                                                                                            }//10
                        public String getInvetoryHardware()
                                                                                              {//11
                        return inventoryHardware;
                                                                                                }//11
                                                          public double getUnitPrice()
                                                                                                   {//12
                                                     return unitPrice;
                                                                                                     }//12
                                                          public double getQuantityStock()
                                                                                                           {//13
                                                    return quantityStock;
                                                                                                            }//13
                                                          public String getInventoryHardware()
                                                                                                                  {//14
                                                    return inventoryHardware;
                                                                                                                   }//14
                                                                               public double computeinventoryValue()
                                                                                                                        {//15
                                                                          return quantityStock * unitPrice;
                                                                                                                            }//15
                                                                                 public double computetotalInventory()
                                                                                                                                {//16
                                                               return totalInventory = totalInventory + inventoryValue;
                                                                                                                                  }//16               
                                                                                     public String toString()
                                                                                                                                  {//17
                                                                               return (itemName);
                                                                                                                                    }//17
            }//2
         }//40
                            // SubItem.java
                            // Sub class to main program
         public class SubItem extends Item
        {//18
                  private String inventoryHardware;
                  private double restockingFee = .05;
                        public SubItem(double UnitPrice,double QuantityStock,int InventoryHardware,int
                                               ItemNumber,String ItemName)
              {//19
                   setUnitPrice(UnitPrice);
                   setQuantityStock(QuantityStock);
                   setItemNumber(ItemNumber);
                   setItemName(ItemName);
                   inventoryHardware = InventoryHardware;
               }//19
                  public void setInventoryHardware(String InventoryHardware)
                       {//20
                     inventoryHardware = InventoryHardware;
                       }//20
                      public int getInventoryHardware()
                               {//21
                      return inventoryHardware;
                                }//21
                              public double computeRestockingFee()
                                       {//22
                    return ((getUnitPrice() * getQuantityStock()) * restockingFee);
                                        }//22
            }//18
                   private static BufferedReader stdin = new BufferedReader( new InputStreamReader(      
                    System.in ) );
                  private static int totalCount = 5;
          public Inventory4()
             {//23
         double unitPrice; // Unit price of each item
         double quantityStock; // Number of items in stock
         double inventoryValue; // Place holder for calculated inventory value
         double totalInventory; // Place holder for calculated total inventory value
         int itemNumber; // Item Number
         String itemName = ""; // Name of each item
                }//23
       public static void main(String[] args)throws IOException
           {//24
         SubItem myItem[];
          myItem = new SubItem[5];
        myItem[0] = new SubItem(10.35,20,4,1,"Traxx");
        myItem[1] = new SubItem(176.34,10,5,2,"Panels");
        myItem[2] = new SubItem(85.34,4,4,3,"Surfaces");
        myItem[3] = new SubItem(1.95,56,6,4,"Brackets");
        myItem[4] = new SubItem(82.34,8,1,5,"Overheads");
             printArray(myItem);
             myItem = sortArray(myItem);
             System.out.println(" Inventory List Sorted by Items \n\n");
              printArray(myItem);
        ItemButton itemButton = new ItemButton(myItem,totalCount); // Make ItemButton
        itemButton.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        itemButton.setSize( 350,390 ); // Window size
        itemButton.setVisible( true ); // display window
                   } //24 End Main Method
          private static SubItem[] printArray(SubItem[] myItem)
                          {//25
              double totalInventory = 0;
              double restockingFee = 0;
                         for (int i = 0; i<5;++i)
                          {//26
                               System.out.println("\n The Item Number is " + i + myItem.getItemNumber() );
                               System.out.println("\n Item Name is " + myItem.getItemName() );
                               System.out.println("\n Quantity in Stock is " + myItem.getQuantityStock() );
                               System.out.println("\n Inventory Hardware " +                                                    
                  myItem.getInventoryHardware() );
                               System.out.println("\n Inventory Value is $" + myItem.computeinventoryValue          
                               totalInventory = totalInventory + myItem.computeinventoryValue();
                               restockingFee = totalInventory + myItem.computeRestockingFee();
                                  } //26 End For Loop
                                   System.out.println("\n Total Value of all inventory is " + totalInventory);
                                   System.out.println("\n Total Value of all inventory with restock fee $" +             
                                       restockingFee);
                                   return myItem;
                                    }//25
       private static SubItem[] sortArray(SubItem[] myItem)
    {//27
          SubItem temp = new SubItem();
              int i, j;
             int array_size = 5;
             for (i = (array_size - 1); i >= 0; i--)
         {//28
                 for (j = 1; j <= i; j++)
               {//29
                       if (myItem[j-1].getItemName().compareTo(myItem[j].getItemName()) > 1)
                   {//30
                      temp = myItem[j-1];
                      myItem[j-1] = myItem[j];
                      myItem[j] = temp;
                    } //30 End if
                 } //29 End inner for loop
            } //28 End outer for loop
                              return myItem;
    } //27 End Method
    }//1
    // ItemButton.java
    // This will create GUI buttons.
    // Display the Items.
    import java.awt.FlowLayout;//line252
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JOptionPane;
    import javax.swing.SwingConstants;
      public class ItemButton extends JFrame
          {//31
            private JButton nextJButton; // text button
            private JButton prevJButton; // icon button
            private JLabel lblItemName; // text field with set size
            private JTextField txtItemName; // text field constructed with text
            private JTextField textField3; // text field with text and size
            private JLabel lblItemNumber; // text field with set size
            private JTextField txtItemNumber; // text field constructed with text
            private JLabel lblUnitPrice; // text field with set size
            private JTextField txtUnitPrice; // text field constructed with text
            private JLabel lblQuantityStock; // text field with set size
            private JTextField txtQuantityStock; // text field constructed with text
            private JLabel lblInventoryHardware; // text field with set size
            private JTextField txtInventoryHardware; // text field constructed with text
            private JLabel lblcomputeRestockingFee; // text field with set size
            private JTextField txtcomputeRestockingFee; // text field constructed with text
            private JLabel lblcomputeinventoryValue; // text field with set size
            private JTextField txtcomputeinventoryValue; // text field constructed with text
            private JLabel lblcomputetotalInventory; // text field with set size
            private JTextField txtcomputetotalInventory; // text field constructed with text
                SubItem[] arraySubItem;
                private int currentArrayCounter;
                private int arrayCount;
                   public ItemButton(SubItem[] myItem, int totalArrayCount)
           {//32
                    super ( "Inventory" );
                    arraySubItem = myItem;
                    arrayCount = totalArrayCount;
                    currentArrayCounter = 0;
                    setLayout( new FlowLayout() ); // set frame layout
                         Icon iconNext = new ImageIcon( getClass().getResource( "" ) );
                         Icon iconPrev = new ImageIcon( getClass().getResource( "" ) );
                                   lblItemName = new JLabel( "Item Name ");
                                   add( lblItemName ); // textField3 to JFrame
                                   txtItemName = new JTextField( "", 15 );
                                   add( txtItemName ); // add textField3 to JFrame
                                   lblItemNumber = new JLabel( "Item Number ");
                                   add( lblItemNumber ); // textField3 to JFrame
                                   txtItemNumber = new JTextField( "", 15 );
                                   add( txtItemNumber ); // add textField3 to JFrame
                                   lblUnitPrice = new JLabel( "Unit Price ");
                                  add( lblUnitPrice ); // textField3 to JFrame
                                  txtUnitPrice = new JTextField( "", 15 );
                                  add( txtUnitPrice ); // add textField3 to JFrame
                                  lblQuantityStock = new JLabel( "Quantity Stock " );
                                  add( lblQuantityStock ); // textField3 to JFrame
                                  txtQuantityStock = new JTextField( "", 15 );
                                  add( txtQuantityStock ); // add textField3 to JFrame
                                  lblInventoryHardware = new JLabel( "Inventory Hardware " );
                                 add( lblInventoryHardware ); // textField3 to JFrame
                   txtInventoryHardware = new JTextField( "", 15 );
                                 add( txtInventoryHardware ); // add textField3 to JFrame
                                 lblcomputeRestockingFee = new JLabel( "Restocking Fee ");
                                 add( lblcomputeRestockingFee ); // textField3 to JFrame
                                 txtcomputeRestockingFee = new JTextField( "", 15 );
                                 add( txtcomputeRestockingFee ); // add textField3 to JFrame
                                  lblcomputeinventoryValue = new JLabel( "Inventory Value " );
                                  add( lblcomputeinventoryValue ); // textField3 to JFrame
                                  txtcomputeinventoryValue = new JTextField( "", 15 );
                                  add( txtcomputeinventoryValue ); // add textField3 to JFrame
                                  lblcomputetotalInventory = new JLabel( "Total Inventory ");
                                  add( lblcomputetotalInventory ); // textField3 to JFrame
                                  txtcomputetotalInventory = new JTextField( "", 15 );
                                  add( txtcomputetotalInventory ); // add textField3 to JFrame
                   nextJButton = new JButton( "Next" ); // button with Next
                   prevJButton = new JButton( "Previous"); // button with Prev
                   add(prevJButton);
                   add(nextJButton); // add plainJButton to JFrame
                     ButtonHandler handler = new ButtonHandler();
                                          nextJButton.addActionListener( handler );
                                          prevJButton.addActionListener( handler );
                                          setTextFields();
    } //32 End ButtonFrame constructor
            private class ButtonHandler implements ActionListener
       {//33
          public void actionPerformed( ActionEvent event )
         {//34
               if (event.getActionCommand()== "prevJButton")
             {//35
                  currentArrayCounter++;
              }//35
                 else
                    {//36
                  currentArrayCounter++;
                      }//36
                        setTextFields();
           } //34 End Method ActionPerformed
    } //33 End Private inner class ButtonHandler
    private void setTextFields()
    {//37
               if (currentArrayCounter == arrayCount)
                  {//38
                     currentArrayCounter = 0;
                     }//38
               if (currentArrayCounter < 0)
                    {//39
                       currentArrayCounter = arrayCount;
                      }//39
                           txtItemName.setText(arraySubItem[currentArrayCounter].getItemName());
                           txtItemNumber.setText(arraySubItem[currentArrayCounter].getItemNumber()          
                  +"");
                           txtUnitPrice.setText(arraySubItem[currentArrayCounter].getUnitPrice()+"");
                           txtQuantityStock.setText(arraySubItem[currentArrayCounter].getQuantityStock      
                  ()+"");
                            txtInventoryHardware.setText(arraySubItem                           
    [currentArrayCounter].getInventoryHardWare()+"");
                            txtcomputeRestockingFee.setText(arraySubItem                           
    [currentArrayCounter].computeRestockingFee()+"");
                            txtcomputeinventoryValue.setText(arraySubItem                           
    [currentArrayCounter].computeinventoryValue()+"");
                            txtcomputetotalInventory.setText(arraySubItem                             
    [currentArrayCounter].computetotalInventory()+"");
      }//37
    } //31 End class ItemButton

  • APPLESTUDIO DISPLAY 17"(ADC/CRT) - possible to add external power?

    Hi there,
    is it possible to add some external power to this monitor(12v)?
    APPLESTUDIO DISPLAY 17"(ADC/CRT) :
    http://www.everymac.com/monitors/apple/studiocinema/specs/apple_studio_display_17cl.html
    Are there any technical schematics to download?
    In theory one should find the power cables that is normally integrated in the ADC cable?
    Many thanks,
    CF

    The best solution would to buy a new graphics card that can support 2 inputs. Certain applications/tasks (like video editing) don't handle 2nd card well. So I have never ran a PCI card for my second monitor. You'll have to specify what you intend to do with your graphics card for better recomendations of cards that just aren't overkill for your usage. All of my systems use Dr bott connectors & I have never had a problem with them. Depending on what card you buy you may need one or two of the ADC to DVI connectors on the site. Best of luck
    http://www.drbott.com/prod/db.lasso?code=0111-DVAD

  • A small prob...

    Hi,
    i am akila.i have a small problem with my program. i will copy both my program and error... If anybody can make it out... plz reply...
    this is the program
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    @SuppressWarnings("serial")
    public class Events extends JPanel implements ActionListener
         final static String newline="\n";
         JLabel l;
         JTextArea a;
         JButton b;
         Events()
              l = new JLabel("Just checkin");
              add(l,BorderLayout.BEFORE_FIRST_LINE);
              b = new JButton("This is it!!!");
              add(b,BorderLayout.AFTER_LINE_ENDS);
              b.addActionListener(this);
              a = new JTextArea(5,20);
              a.setEditable(true);
              add(a,BorderLayout.CENTER);
              JScrollPane scrollPane = new JScrollPane(a);
              add(scrollPane, a);
         public void actionPerformed(ActionEvent e)
              String s=e.getActionCommand();
              System.out.println(s);
              a.append(s+newline);
              a.setCaretPosition(a.getDocument().getLength());
         public static void Create()
              JFrame frame = new JFrame("Event handler trial");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JComponent newContentPane = new Events();
              JMenuBar j = new JMenuBar();
              j.setPreferredSize(new Dimension(200,20));
              j.setBackground(new Color(100,100,100));
              j.setOpaque(true);
              frame.setJMenuBar(j);
              newContentPane.setOpaque(true); //content panes must be opaque
              frame.setContentPane(newContentPane);
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args)
              javax.swing.SwingUtilities.invokeLater(new Runnable()
                   public void run()
                        Create();
    This is the error...
    This is it!!!
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
         at Events.actionPerformed(Events.java:41)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at javax.swing.JComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)

    Hi akila. Your code compiles and runs fine when I tried it.
    Which is line 41? (The stack trace is saying that something on that line is null.) The line "a.setCaretPosition(a.getDocument().getLength());" looks OK.

  • Gui xalan xml

    I am trying to program a java swing gui with one button that will
    transform old.xml to new.xml using transform.xsl using xalan
    but the compiler gives an error message:
    Transform2.java:53: unreported exception javax.xml.transform.TransformerException; must be caught or declared to be thrown
    transformation("hamlet.xml","transformation1.xsl","hamletnew.xml"
    anyone know the solution of this problem
    this is the complete code:
    //using apache xalan to transform old.xml with tranform.xsl into new.xml
    //with java swing gui
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    public class Transform2
    public static void main(String[] args)throws TransformerException, TransformerConfigurationException,FileNotFoundException, IOException
    JFrame frame = new JFrame("Event Handling Tombol & TextField");
    final JButton button = new JButton("Transform");
    ActionListener eventclick =
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button) {
    transformation("old.xml","transform.xsl","new.xml");
    button.addActionListener(eventclick);
    frame.getContentPane().setLayout(new FlowLayout());
    frame.getContentPane().add(button);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    private static void transformation(String inputfile,String xslfile,String outputfile)throws TransformerException, TransformerConfigurationException,FileNotFoundException, IOException
    // Use the static TransformerFactory.newInstance() method to instantiate
    // a TransformerFactory. The javax.xml.transform.TransformerFactory
    // system property setting determines the actual class to instantiate --
    // org.apache.xalan.transformer.TransformerImpl.
    TransformerFactory tFactory = TransformerFactory.newInstance();
    // Use the TransformerFactory to instantiate a Transformer that will work with
    // the stylesheet you specify. This method call also processes the stylesheet
    // into a compiled Templates object.
    Transformer transformer = tFactory.newTransformer(new StreamSource(xslfile));
    // Use the Transformer to apply the associated Templates object to an XML document
    // (foo.xml) and write the output to a file (foo.out).
    transformer.transform(new StreamSource(inputfile), new StreamResult(new FileOutputStream(outputfile)));

    Function
    private static void transformation(String inputfile,String xslfile,String outputfile)throws TransformerException, TransformerConfigurationException,FileNotFoundException, IOExceptionStates that that function might throw an on of the exceptions mentioned.. to do this you have to have
    try{
       //the code that this function should do...
    catch(Exception e)
        // if doing previous stuff fails... this will be executed.
        // here do the throwing..
        throw new IOException (this);
    }also the main function propably should not throw exceptions..
    P_s

  • Xalan gui xml

    I am trying to program a java swing gui with one button that will
    transform old.xml to new.xml using transform.xsl using xalan
    but the compiler gives an error message:
    Transform2.java:53: unreported exception javax.xml.transform.TransformerException; must be caught or declared to be thrown
    transformation("hamlet.xml","transformation1.xsl","hamletnew.xml"
    anyone know the solution of this problem
    this is the complete code:
    //using apache xalan to transform old.xml with tranform.xsl into new.xml
    //with java swing gui
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    public class Transform2
    public static void main(String[] args)throws TransformerException, TransformerConfigurationException,FileNotFoundException, IOException
    JFrame frame = new JFrame("Event Handling Tombol & TextField");
    final JButton button = new JButton("Transform");
    ActionListener eventclick =
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button) {
    transformation("old.xml","transform.xsl","new.xml");
    button.addActionListener(eventclick);
    frame.getContentPane().setLayout(new FlowLayout());
    frame.getContentPane().add(button);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    private static void transformation(String inputfile,String xslfile,String outputfile)throws TransformerException, TransformerConfigurationException,FileNotFoundException, IOException
    // Use the static TransformerFactory.newInstance() method to instantiate
    // a TransformerFactory. The javax.xml.transform.TransformerFactory
    // system property setting determines the actual class to instantiate --
    // org.apache.xalan.transformer.TransformerImpl.
    TransformerFactory tFactory = TransformerFactory.newInstance();
    // Use the TransformerFactory to instantiate a Transformer that will work with
    // the stylesheet you specify. This method call also processes the stylesheet
    // into a compiled Templates object.
    Transformer transformer = tFactory.newTransformer(new StreamSource(xslfile));
    // Use the Transformer to apply the associated Templates object to an XML document
    // (foo.xml) and write the output to a file (foo.out).
    transformer.transform(new StreamSource(inputfile), new StreamResult(new FileOutputStream(outputfile)));

    Crossposted in 4 places.

  • Xalan gui

    I am trying to program a java swing gui with one button that will
    transform old.xml to new.xml using transform.xsl using xalan
    but the compiler gives an error message:
    Transform2.java:53: unreported exception javax.xml.transform.TransformerException; must be caught or declared to be thrown
    transformation("hamlet.xml","transformation1.xsl","hamletnew.xml"
    anyone know the solution of this problem
    this is the complete code:
    //using apache xalan to transform old.xml with tranform.xsl into new.xml
    //with java swing gui
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    public class Transform2
    public static void main(String[] args)throws TransformerException, TransformerConfigurationException,FileNotFoundException, IOException
    JFrame frame = new JFrame("Event Handling Tombol & TextField");
    final JButton button = new JButton("Transform");
    ActionListener eventclick =
    new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == button) {
    transformation("old.xml","transform.xsl","new.xml");
    button.addActionListener(eventclick);
    frame.getContentPane().setLayout(new FlowLayout());
    frame.getContentPane().add(button);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    private static void transformation(String inputfile,String xslfile,String outputfile)throws TransformerException, TransformerConfigurationException,FileNotFoundException, IOException
    // Use the static TransformerFactory.newInstance() method to instantiate
    // a TransformerFactory. The javax.xml.transform.TransformerFactory
    // system property setting determines the actual class to instantiate --
    // org.apache.xalan.transformer.TransformerImpl.
    TransformerFactory tFactory = TransformerFactory.newInstance();
    // Use the TransformerFactory to instantiate a Transformer that will work with
    // the stylesheet you specify. This method call also processes the stylesheet
    // into a compiled Templates object.
    Transformer transformer = tFactory.newTransformer(new StreamSource(xslfile));
    // Use the Transformer to apply the associated Templates object to an XML document
    // (foo.xml) and write the output to a file (foo.out).
    transformer.transform(new StreamSource(inputfile), new StreamResult(new FileOutputStream(outputfile)));

    Your transformation method is declared to throw a number of exceptions. You need to handle these in your actionPerformed method (probably displaying an error message to the user to indicate what went wrong).

  • Why have inner classes

    Well I can understand the purpose of inner classes in multithreaded applications or where you need a continous monitoring, but I have always been wondering why use an inner application in a normal application. Any ideas?

    I guess you mean "inner class in a normal applications" in the last line of your question? If not, don't mention reading this reply since it doesn't answer your question in the latter case.
    Otherwise, the most common use for inner classes according to me is event handling and out of pure lazyness. Good programmers should be lazy you know.
    Let me give an example:
    public class Test() extends Applet{
    <some code here>
    private class Handler extends MouseAdapter(){
    public void mouseEntered(MouseEvent evt){
    <some event handling>
    In the example above we have an applet in which we want to do some MouseEvent handling.
    You could implement the mouselistener in your applet or you could create an inner class that extends MouseAdapter.
    When you implement the MouseListener interface, you have to define all methods from this interface in your applet to prevent it from being abstract.
    When you use an innerclass you only have to provide the method which you want to override, all the other are already implemented by extends the adapter.
    Another advantage of innerclasses is that you have access to all classvariables of the class in which you defined your inner class.
    I hope this can be a little help for you.

Maybe you are looking for

  • My iPod touch 4th generation charger won't work!

    I have a black 4th gen. iPod touch with 5.1 iOS. The charger won't work anymore and I think something is cut in the wire. If I get a new one do I have to pay, if so were can I get one?

  • Can I set MP3 files as "Podcast" so that I can get the blue "Unplayed" dot?

    Here's my scenario: I have a whole bunch of audio files of Spanish lessons that are in MP3 format that I want to put on to my iPod. There's quite a lot of them: 82 in fact, and they're titled lesson 1, lesson 2, lesson 3, etc. In order for me to be a

  • Wet610n connecting to netgear WDS setup

    Hey, Been trying to get a wet610n to connect to the following setup: netgear wndr3700 router: the router has bridging and repeating enabled with the mac addresses of the netgear wn802t repeater and the linksys wet610n bridge in its table. The netgear

  • Simple ALV (oops)

    hi I am new to OOPs concept.In this cl_gui_alv_grid,What are all the method used to display the alv grid. This is my coding ,While executing it is not showing anything ,I dont know exatly wt is the problem I check with standard program am not able to

  • Error when attempting to Save as... in CS5

    Hello, Occasionally when attempting to Save as... in CS5 it will give me an error saying that the file doesn't exist and to verify the filepath and try again. We are attempting to save to an external hard drive which is close to full but not complete