Creating an JButton that implements EventListener

Hi all
im at university and have a question that was in one of my java books. Im learning about event handling
and adding EventListeners to components. But there was a one part of my book that talked about defining a new class of JButton
that extends JButton and implemented ActionListener that could listen for itself being clicked.
so i could just create instances of this button.
could someone explain this idea to me or show me a tutorial on it i tryed googe but i could not find
anything that helped.

JustSomeGuy wrote:
I was just kidding in my last response, as that is the same thing as calling system.exit.
Making a generic "Exit" EventListner is also a good ideal, but that doesn't mean you can't make a generic "exit" button as well.
The way I personally handle it is I always have a CleanUp method in my code, typically in the same class as main is. If it is not threaded, or is a simple GUI (differentiated because swing GUI's are always multithreaded) then the method does contain system.exit(0), usually right after dispose() without much else. If it is multithreaded, then that is another story. My generic "Exit" button, which is actually on my netbeans pallette, simply calls CleanUp. I think I have one for menu exit items too, not sure I would have to check.
JSGCalls cleanUp where? I'm not really seeing the advantage. You call System.exit()? Hmmmm

Similar Messages

  • How to create a WebService that implements a given WSDL

    Hi
    I am implementing a webservice that will be a subscriber for
    another external webservice. The provider of the external
    webservice will give me the WSDL for the subscribers he
    expects. So, I'll have to setup a webservice that implements
    the WSDL provided to me.
    Would this be possible to do with WL7 ? Typically, one implements
    a webservice using EJBs and such within WL, and the servicegen
    script then creates the WSDL. However, this case is sort of in
    reverse where the WSDL is already available and I need to
    create a service that complies with this ...
    thanx
    -john

    That still holds true.
    Mike wrote:
    Any updated info on when that will ship?
    Last I heard it was 20-SEP?
    Mike
    "manoj cheenath" <[email protected]> wrote in message
    news:[email protected]..
    you need to wait for 7.0 sp1 which got a wsdl2service
    ant task.
    regards,
    -manoj
    "john" <[email protected]> wrote in message news:[email protected]..
    Hi
    I am implementing a webservice that will be a subscriber for
    another external webservice. The provider of the external
    webservice will give me the WSDL for the subscribers he
    expects. So, I'll have to setup a webservice that implements
    the WSDL provided to me.
    Would this be possible to do with WL7 ? Typically, one implements
    a webservice using EJBs and such within WL, and the servicegen
    script then creates the WSDL. However, this case is sort of in
    reverse where the WSDL is already available and I need to
    create a service that complies with this ...
    thanx
    -john
    Rajesh Mirchandani
    Developer Relations Engineer
    BEA Support

  • How to create a JButton that can run other Apps?

    Hi, Every1
    i want to create a JButton which can let the user click it and it runs a
    specified installed app in the system ( say, a JButton that fires up MS
    Outlook). how can i do that?
    thank you very much.
    Yu.

    hi, if i want to execute some kind of the following, how would i handle it?
    mailto:[email protected]
    i tried: Runtime.getRuntime().exec("mailto:[email protected]");
    but it gave me java.io.IOException: CreateProcess: mailto:[email protected] error=2
    i think this problem would be relatively easy but i just cant figure out.
    thanks

  • Creating a JButton for each line in a txt file

    I need to know how to creating a JButton for each line in a txt file then add an actionListener to the number of buttons (note they are in a JTable). Here is a clipet of code thanx for the help (note that this is one part of a program i am making there are 2 more classes. If u need them just ask) Thanx:
    class Diary extends JFrame implements ActionListener {
         private JTextArea note;
         private JTextField name;
         private JMenuBar menu = new JMenuBar();
         private JMenu file, edit, font, background, tcolor, settings, help;
         private JMenuItem nu, copy, paste, save, exit, b8, b10, b12, b14, b16, b18, b20, b24, b30, bblue, bred, bgreen, bpink, cblue, cred, cgreen, cpink, eset, nver, using, about;
         private String[] columnNames = {
              "File"
         private Vector dat = new Vector();
         private JTable filetable;
         public Diary() {
              setSize(new Dimension(500, 500));
              setTitle("Diary 2.00");
              file = new JMenu("File");
              menu.add(file);
              nu = new JMenuItem("new");
              nu.addActionListener(this);
              file.add(nu);
              file.add(new JSeparator());
              copy = new JMenuItem("copy");
              copy.addActionListener(this);
              file.add(copy);
              paste = new JMenuItem("paste");
              paste.addActionListener(this);
              file.add(paste);
              file.add(new JSeparator());
              save = new JMenuItem("Save");
              save.addActionListener(this);
              file.add(save);
              file.add(new JSeparator());
              exit = new JMenuItem("exit");
              exit.addActionListener(this);
              file.add(exit);
              edit = new JMenu("Edit");
              menu.add(edit);
              font = new JMenu("font");
              edit.add(font);
              b8 = new JMenuItem("8");
              b8.addActionListener(this);
              font.add(b8);
              b10 = new JMenuItem("10");
              b10.addActionListener(this);
              font.add(b10);
              b12 = new JMenuItem("12");
              b12.addActionListener(this);
              font.add(b12);
              b14 = new JMenuItem("14");
              b14.addActionListener(this);
              font.add(b14);
              b16 = new JMenuItem("16");
              b16.addActionListener(this);
              font.add(b16);
              b18 = new JMenuItem("18");
              b18.addActionListener(this);
              font.add(b18);
              b20 = new JMenuItem("20");
              b20.addActionListener(this);
              font.add(b20);
              b24 = new JMenuItem("24");
              b24.addActionListener(this);
              font.add(b24);
              b30 = new JMenuItem("30");
              b30.addActionListener(this);
              font.add(b30);
              background = new JMenu("background");
              edit.add(background);
              bblue = new JMenuItem("blue");
              bblue.addActionListener(this);
              background.add(bblue);
              bred = new JMenuItem("red");
              bred.addActionListener(this);
              background.add(bred);
              bgreen = new JMenuItem("green");
              bgreen.addActionListener(this);
              background.add(bgreen);
              bpink = new JMenuItem("pink");
              bpink.addActionListener(this);
              background.add(bpink);
              tcolor = new JMenu("text color");
              edit.add(tcolor);
              cblue = new JMenuItem("blue");
              cblue.addActionListener(this);
              tcolor.add(cblue);
              cred = new JMenuItem("red");
              cred.addActionListener(this);
              tcolor.add(cred);
              cgreen = new JMenuItem("green");
              cgreen.addActionListener(this);
              tcolor.add(cgreen);
              cpink = new JMenuItem("pink");
              cpink.addActionListener(this);
              tcolor.add(cpink);
              settings = new JMenu("Settings");
              menu.add(settings);
              eset = new JMenuItem("Edit Settings");
              eset.addActionListener(this);
              settings.add(eset);
              help = new JMenu("Help");
              menu.add(help);
              using = new JMenuItem("Using");
              using.addActionListener(this);
              help.add(using);
              about = new JMenuItem("About");
              about.addActionListener(this);
              help.add(about);
              help.add(new JSeparator());
              nver = new JMenuItem("new Versions");
              nver.addActionListener(this);
              help.add(nver);
              note = new JTextArea("");
              try {
                   BufferedReader filein = new BufferedReader(new FileReader("files.txt"));
                   String sfile;
                   while ((sfile = filein.readLine()) != null) {
                        //add buttons per each line of the txt file and show em
              catch (FileNotFoundException ioe) {
                   JOptionPane.showMessageDialog(null, "Iternal Error, contact [email protected] if the error persists", "", JOptionPane.WARNING_MESSAGE);
              catch (IOException ioe) {
                   JOptionPane.showMessageDialog(null, "Iternal Error, contact [email protected] if the error persists", "", JOptionPane.WARNING_MESSAGE);JOptionPane.showMessageDialog(null, "Iternal Error, contact [email protected] if the error persists", "", JOptionPane.WARNING_MESSAGE);
              String[][] data = new String[dat.size()][];
              for (int x = 0; x < dat.size(); x++) {
                   data[x] = (String[])dat.get(x);
              filetable = new JTable(data, columnNames);
              filetable.setPreferredScrollableViewportSize(new Dimension(100, 500));
              JScrollPane scrollpane = new JScrollPane(filetable);
              name = new JTextField("diary");
              JPanel main = new JPanel(new GridLayout(0, 1));
              getContentPane().add(note);
              getContentPane().add(name, BorderLayout.SOUTH);
              getContentPane().add(scrollpane, BorderLayout.WEST);
              setJMenuBar(menu);
         public void actionPerformed(ActionEvent e) {
              if (e.getSource() == nu) {
                   int nuask = JOptionPane.showConfirmDialog(Diary.this, "Are you sure you want to make a new entry?\nThis will erease any unsaved entry's!!");
                   if (nuask == JOptionPane.YES_OPTION) {
                        note.setText("");
                        note.setBackground(Color.WHITE);
                        note.setForeground(Color.BLACK);
              if (e.getSource() == copy) {
                   note.copy();
              if (e.getSource() == paste) {
                   note.paste();
              if (e.getSource() == save) {
                   try {
                        String sn = name.getText();
                    FileWriter outputStream = new FileWriter("saved/" + sn + ".txt");                            
                    setTitle("Diary 1.00 : " + sn);
                    outputStream.write(note.getText());
                    outputStream.close();
                catch(IOException ioe) {
                     System.out.println("IOException");
              if (e.getSource() == exit) {
                   int exitask = JOptionPane.showConfirmDialog(Diary.this, "Are you sure you want to exit? Any unsaved entries will be deleted");
                   if (exitask == JOptionPane.YES_OPTION) {
                        System.exit(0);
              if (e.getSource() == b8) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),8));
              if (e.getSource() == b10) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),10));
              if (e.getSource() == b12) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),12));
              if (e.getSource() == b14) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),14));
              if (e.getSource() == b18) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),18));
              if (e.getSource() == b20) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),20));
              if (e.getSource() == b24) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),24));
              if (e.getSource() == b30) {
                   note.setFont(new Font(note.getFont().getName(),note.getFont().getStyle(),30));
              if (e.getSource() == bblue) {
                   note.setBackground(Color.BLUE);
              if (e.getSource() == bred) {
                   note.setBackground(Color.RED);
              if (e.getSource() == bgreen) {
                   note.setBackground(Color.GREEN);
              if (e.getSource() == bpink) {
                   note.setBackground(Color.PINK);
              if (e.getSource() == cblue) {
                   note.setForeground(Color.BLUE);
              if (e.getSource() == cred) {
                   note.setForeground(Color.RED);
              if (e.getSource() == cgreen) {
                   note.setForeground(Color.GREEN);
              if (e.getSource() == cpink) {
                   note.setForeground(Color.PINK);
              if (e.getSource() == eset) {
                   new UserSettings().setVisible(true);
              if (e.getSource() == about) {
                   JOptionPane.showMessageDialog(null, "Created by Collin Doering 2005 in Gr.9\n\nErrors:\n------------------------------------------------------------------\n1. No File Encryption\n2. No user and password Encryption", "", JOptionPane.INFORMATION_MESSAGE );
              if (e.getSource() == nver) {
                   JOptionPane.showMessageDialog(null, "New Version |3.00| expected July, 2005\n\nNew Features\n----------------------------------------------\n1. File Encryption\n2. User File Encryption\n3. Full help dialog\n4. More Text changing features", "", JOptionPane.INFORMATION_MESSAGE);
              if (e.getSource() == using) {
                   JOptionPane.showMessageDialog(null, "Go ask Collin Doering\[email protected]", "", JOptionPane.INFORMATION_MESSAGE );
    THANK YOU

    so i still do not understand how i would create one
    button per each line in a txt flle then read in the
    file that the txt file specified.This assumes you know how many lines there are in the file.
    If not, modify as per my prior post
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      String[] linesInFile = {"Hello","World","Goodbye","Now"};
      JButton[] btn = new JButton[linesInFile.length];
      public Testing()
        setLocation(200,200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel jp = new JPanel(new GridLayout(0,1));
        for(int x = 0; x < btn.length; x++)
          btn[x] = new JButton(linesInFile[x]);//<---this would be where file.readLine() goes
          jp.add(btn[x]);
          btn[x].addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae){
              JOptionPane.showMessageDialog(getContentPane(),ae.getActionCommand());}});
        getContentPane().add(jp);
        pack();
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • PropertyChangeListener for a JButton that contains a JPanel?

    I created a class that extends from the JButton class. The class contains a JPanel that adds two components to the panel, A JLabel that contains text and a JLabel that contains an icon. Therefore this class is really just a button that contains a JPanel with 2 JLabels added to the panel. (Reason for doing this is it adds layout control to add the 2 components to a panel instead of directly to the JButton) Normally you would do a changepropertylistener to the JButton but because I added the 2 components (JLabel) to a panel and then added the JPanel to the button, the button doesn't notice any change events. How would I detect the PropertyChangeEvent for this cenario?
    thanks,
    Peter Landis

    The solution to the problem is when the instance of the class is created, do a getComponent(0) to get the JPanel component and the do a getComponent(0) to get the JLabel component. Now from here you can add a PropertyChangeListener to the JLabel that you just obtained. The PropertyChangeListener class will look like:
    class RotorItemListener implements PropertyChangeListener
         public void propertyChange(PropertyChangeEvent e)
    System.out.println("CHANGE");
    String name = e.getPropertyName();
    if(name == "text")
    System.out.println("Label changed");
    This will only trap a change that occurs when the label has changed. If you omit the if(name == "text") then when the component is created, a property change event will be triggered which is not what you want. This only traps event that occur only when a change has occurred on the JLabel. Notice that during the instantiation of the component you'll see the text displayed "CHANGE" and not the "Label changed" until the label text has changed.
    Pretty cool huh!

  • Any way to create a form that allows users to create profiles that can be viewed by other users?

    I'm working on a social media site, and I would like to give users the ability to create simple profiles that can be viewed by other users. Is there any way I can do this in Muse CC? Any good resource websites with code I can embed?

    Muse form widgets can only email the form submission data to a specified email address for non-BC hosting at this time. For BC with webCommerce plan and above, this should be possible with the help of webApps however, that is an advanced topic and would require some knowledge of CMS and HTML to implement <http://helpx.adobe.com/business-catalyst/partner/web-apps.html>.
    Also this will not be possible with Muse on its own as Muse outputs static pages only and what you are looking for requires backend technology to work (that BC offers).
    Thanks,
    Vinayak

  • How can I create a subVI that has state?

    I'm trying to simplify a VI that I inherited and I noticed a recurring pattern that IMHO should be a subVI.  The pattern is that we have a digital output line that is controlled by a timer.  Each output has a start time for it to activate and a duration after which it is turned off.  When the state changes, a single line entry is added to a common log file and an indicator shared variable is set so that the remote host VI updates.  We have a big while loop that checks the current time against each of the activation conditions.  To detect when the state has changed, we're using a shift register (for each actuator).  It's one thing to see the same pattern 3 times, but it's worse -- we want to sometimes use a different number of actuators.  If I was writing this in C++ (with which I'm far more comfortable than LabView), I'd write a class for the actuator and instantiate it N times.  The class would have member data to keep track of its state.  I can create a subVI that does the meat of the design pattern, but I can't figure out how to store the previous state in the subVI without requiring it to be passed in.  How do I keep the state and behavior of a VI together?  Surely there's a way to do this because otherwise I can't see how you could implement state-ful algorithms like, say, a PID controller.  But I'm at a loss to figure it out ...
    Thanks.
    Keith.

    To save state in a subVI and not use that state in other subVI calls, make the subVI reentrant.  When a subVI that is reentrant is called it creates a unique memory space for that subVI.  This is called a clone.  That memory space is where state is held for that subVI.  Keep in mind that it also means that the memory footprint is going to be larger.
    To set a subVI to be reentrant, open it and go to File -> VI Properties and select execution.  It will be a choice on the bottom left.
    Hope that this helps,
    Bob Young
    Bob Young - Test Engineer - Lapsed Certified LabVIEW Developer
    DISTek Integration, Inc. - NI Alliance Member
    mailto:[email protected]

  • Eclipse: UFL "u212com.dll" that implements this function is missing

    Dear Sirs,
    I try to open one of our reports with the "Crystal Reports for Eclipse 2.0" sample application. Thie report relies on a com based UFL. I get the following error message:
    Crystal Reports Viewer
    Exception yadada...
    UFL "u212com.dll" that implements this function is missing
    OK
    How can I fix this?
    Thanks for your answers.

    The fact that you can see the UFL under 'Additional Functions' tells me that the UFL is compiled as 32 bit. This is good for creating the report in the IDE which is 32 bit. But the app you are building is compiled as 64 bit. But there is no 64 bit UFL(?) that yo have built so far. So, two options;
    1) Build the UFL as "Any CPU". I am not sure if this will actually work. never tried this, but I do know that it is not possible to compile an app using the CR runtime as "Any CPU". E.g.; we always recommend to compile either as 32 bit and \ or 64 bit, not "Any CPU" This may be the case with the UFL, thus the next suggestion.
    2) Compile a second copy of the UFL as 64 bit. You'll then have to use 64 bit GAC and regasm on that dll.
    - Ludek

  • UFL 'u212com.dll' that implements this function is missing

    I am attempting to write a user function library for the crystal reports version that ships with Visual Studio 2010. Following the walkthrough on the Business Objects website (although that is for VS2005) I have successfully created my .dll file and added it to the GAC, and it appears in the function list under 'Additional Functions' in the Crystal Reports formula editor. However when I use the function on in my Windows forms application, I get the error "UFL 'u212com.dll' that implements this function is missing.". This is on my development machine and I have installed the latest service pack for Crystal Reports for VS2010 (64-bit). My OS is Windows 7 64-bit.
    I have two questions:
    1)  What version of the .NET framework should my class library be targeting? My windows forms application targets the .NET framework version 4, but should I be doing the same thing for the .dll for Crystal Reports? It does show up in the formula editor though, so I guess that means that Crystal Reports recognises it correctly.
    2) I have done a search on the PC for the file 'u212com.dll' and it is in the folder C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win64_x64 (and also in the equivalent 32-bit folder) Is this correct, or is there is a specific 64-bit version of this file?
    Or is it something else that I am missing? Thanks in advance for any suggestions.

    The fact that you can see the UFL under 'Additional Functions' tells me that the UFL is compiled as 32 bit. This is good for creating the report in the IDE which is 32 bit. But the app you are building is compiled as 64 bit. But there is no 64 bit UFL(?) that yo have built so far. So, two options;
    1) Build the UFL as "Any CPU". I am not sure if this will actually work. never tried this, but I do know that it is not possible to compile an app using the CR runtime as "Any CPU". E.g.; we always recommend to compile either as 32 bit and \ or 64 bit, not "Any CPU" This may be the case with the UFL, thus the next suggestion.
    2) Compile a second copy of the UFL as 64 bit. You'll then have to use 64 bit GAC and regasm on that dll.
    - Ludek

  • "UFL 'u2ltdate' that implements this function is missing."

    I am working through migrating older reports from a very outdated version of Crystal into a newer version and trialing Crystal Server 2013 with Crystal Reports for Enterprise.  The only problem I am running into is that I have many reports using the NumberToDate function to pull a number string and form it into a date for the report.  I really need this function to work because we rely on it quite heavily.  When I pull reports that use it into my new environment I am given the following error:
    "UFL 'u2ltdate' that implements this function is missing."
    I have found the u2ltdate.dll on the web and transferred it into the following folders: windows/system32 and program files(x86)/SAP BusinessObjects/SAP BusinessObjects Enterprise XI 4.0/win32_x86 and the win64_x64 as well just to be sure.  But to no avail I am still unable to use the NumberToDate function.  I have even tried copying the u2ltdate.dll from our older server, and this doesn't work either.  I really need to get this working as soon as possible.    I don't know if I need a 64 bit dll because it is windows server 2008 or if I don't have it in the right places.  Please help!

    Hi Warre,
    Don't put the ufl into the \windows\system32 folder. Nothing should go there now.
    I doubt this will ever work in CR for Enterprise. It's a Java Designer so the only way to make it work is to create a Java UFL.
    Search for this KBA:
    1803967 - How to make a Java UFL available in Crystal Reports 2011 Designer?
    Same for CR for Ent., you need a Java UFL.
    Only way to make this work is to convert the UFL to Java or use Crystal Reports 2011 or 2013.
    See this MS Forum post I responded to also:
    Custom Crystal DLLs with Crystal Reports 2008 for Visual Studio Run Time
    And this one:
    http://scn.sap.com/docs/DOC-35036
    And this one:
    Java UFL and VB UFL
    Try searching, there is a kbase article with a sample attached.
    And you will need a 64 bit version because some of the report processing servers may be 64 bit only but I believe the Crystal Report Processing Server is 32 bit only. It will need the UFL copied into it's \win32_x86 folder.
    Only issue you should have is using CR for Ent. to design/update/create the reports with that function. Use CR 2011 or 2013 and it should work.
    Problem is we no longer have the source code for that UFL and others, quite often they were written by Support people and therefore not saved into our code source system.
    Don

  • Creating Secure Form that Outputs from a Database?

    I need to create a form that pulls data from a database (of any format) based on what the user enters.  Specifically, I want a customer to be able to enter their name in a field and output data based on their name.  I was about to use a standard PHP mail form methodology, but I realize this would be insecure (I would like to keep my customer list hidden).  Can someone offer a suggestion on what I should look for in creating a secure form/database output structure for my site?  Even if it's just the name of the method so I can search for a tutorial.  Thank you!

    Does it matter that anyone could enter the right name in the form to return the customer data? If so you need to use a password.
    1. Create a form through which the customer can register their details with a user name and password.
    2. On the server side hash the password with something like SHA256 (plenty of open source implementations about or you can create your own).
    3. Store the customer details together with a userid and hashed password in the server database
    4. Create a form through which the customer can request their details, and asks them for their userid and password.
    6. On the server side, rehash the password from the form and request a row from the customer database where the userid and hashed password match an entry
    7. Return the customer data if row retrieved from database else return a message saying on data matching those details etc.
    Regards
    Phil

  • Serializing a class that implements the Singleton pattern

    Hello,
    I am relatively new to Java and especially to serialization so the answer to this question might be obvious, but I could not make it work event though I have read the documentation and the article "Using XML Encoder" that was linked from the documentation.
    I have a class that implements the singleton pattern. It's definition is as follows:
    public class JCOption implements Serializable {
      private int x = 1;
      private static JCOption option = new JCOption();
      private JCOption() {}
      public static JCOption getOption() { return option; }
      public int getX() { return x; }
      public void setX(int x) { this.x = x; }
      public static void main(String args[]) throws IOException {
        JCOption opt = JCOption.getOption();
        opt.setX(10);
        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Test.xml")));
        encoder.setPersistenceDelegate(opt.getClass(),  new JCOptionPersistenceDelegate());
        encoder.writeObject(opt);
        encoder.close();
    }Since this class does not fully comply to the JavaBeans conventions by not having a public no-argument constructor, I have create a class JCOptionPersistenceDelegate that extends the PersistenceDelegate. The implementation of the instantiate method is as follows:
      protected Expression instantiate(Object oldInstance, Encoder out) {
           Expression expression = new Expression(oldInstance, oldInstance.getClass(), "getOption", new Object[]{});
            return expression;
      }The problem is that the resulting XML file only contains the following lines:
        <java version="1.5.0_06" class="java.beans.XMLDecoder">
            <object class="JCOption" property="option"/>
        </java> so there is no trace of the property x.
    Thank you in advance for your answers.

    How about this:
    import java.beans.DefaultPersistenceDelegate;
    import java.beans.Encoder;
    import java.beans.Expression;
    import java.beans.Statement;
    import java.beans.XMLEncoder;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    public class JCOption {
        private int x = 1;
        private static JCOption option = new JCOption();
        private JCOption() {}
        public static JCOption getOption() { return option; }
        public int getX() { return x; }
        public void setX(int x) { this.x = x; }
        public static void main(String args[]) throws IOException {
          JCOption opt = JCOption.getOption();
          opt.setX(10);
          ByteArrayOutputStream os = new ByteArrayOutputStream();
          XMLEncoder encoder = new XMLEncoder( os );
          encoder.setPersistenceDelegate( opt.getClass(), new JCOptionPersistenceDelegate() );
          encoder.writeObject(opt);
          encoder.close();
          System.out.println( os.toString() );
    class JCOptionPersistenceDelegate extends DefaultPersistenceDelegate {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            return new Expression(
                    oldInstance,
                    oldInstance.getClass(),
                    "getOption",
                    new Object[]{} );
        protected void initialize( Class<?> type, Object oldInstance, Object newInstance, Encoder out ) {
            super.initialize( type, oldInstance, newInstance, out );
            JCOption q = (JCOption)oldInstance;
            out.writeStatement( new Statement( oldInstance, "setX", new Object[] { q.getX() } ) );
    }   Output:
    <?xml version="1.0" encoding="UTF-8"?>
    <java version="1.5.0_06" class="java.beans.XMLDecoder">
    <object class="JCOption" property="option">
      <void property="x">
       <int>10</int>
      </void>
    </object>
    </java>

  • Creating an event that reacts to input

    I'm trying to figure out how to create an event that reacts to input from a serial port in J2ME.
    After reading many articles on how to create a custom event in java, I'm having trouble grasping the concept of combining that with input from a serial port connection.
    I understand that I need to create a class for the event, extend EventListener, EventObject, etc. But I'm having trouble figuring out how it's supposed to read when input is available from a serial port.
    Can someone help me understand what I am supposed to do?

    I'm trying to figure out how to create an event that reacts to input from a serial port in J2ME.
    After reading many articles on how to create a custom event in java, I'm having trouble grasping the concept of combining that with input from a serial port connection.
    I understand that I need to create a class for the event, extend EventListener, EventObject, etc. But I'm having trouble figuring out how it's supposed to read when input is available from a serial port.
    Can someone help me understand what I am supposed to do?

  • Transform a class that implements JPanel into a bean.

    I'd to create a bean, from a class that implements JPanel, that in fact is a custom component.
    How can I create a bean?
    I have absolutely no idea about beans.
    What can make beans for me?
    I know a lot about the theory of ejb, is this what I need?
    I'm quite confused, please make me see the light!!!!!
    Thanks.

    Hi Daniel!
    To answer your question short as possible:
    Java -Beans are reusable code - components,
    similar to VB Active -X components,
    which you can use when developing your own
    applications.
    Beans can have a graphic user interface, so you
    can use builder tools like JBuilder or Beanbox
    to show them graphically in a designer.
    You can modify them about their properties,
    mostly shown in a special property window of a
    builder tool.
    It's really not very hard to create your own beans,
    the only thing you have to do is to pack all the
    classes which make the bean into a jar file.
    Then you can import the bean with the builder
    and it will be shown.
    The jar manifest file needs to look like for example:
    Manifest-Version: 1.0
    Name: BeanClock.class
    Java-Bean: True
    All the properties are implemented by public property-get
    and property-set methods, in order to show them in the property window.
    Java is doing that by introspection.
    Hope, this makes it a little bit clearer for you!

  • Hello, I trying to create a program that would run a household furnace. I can't find a way to set timers for the ignitor,flame sensor and blowers. Any thoughts.

    Hello, I'm trying to create a program that would run a household furnace. I can't find a way to set timers foe the ignitor,flame sensor and blowers. Any thoughts would be greatly appreciated. Thanks, primetime

    In the detailed help for the event structure there is a link to caveats and recommendations for using event structures.  It is a good starting point.
    It is courteous to let the Forum know when your questions are related to a school assignment or homework.  We are glad to help you learn LabVIEW, but do not do your homework for you.
    You have learned the major disadvantage of the sequence structure: It must run to completion before anything else can happen.
    If you are building a state machine (typically a while loop with shift registers enclosing a case structure with one case per state) and having trouble with timing, then think about your requirements. Apparently you have some time delays, but under certain conditions you must terminate a delay/wait and do something else.  One way of doing this is to have a Wait state.  The wait state has a short delay, determined by the minimum time you can delay responding to a changed condition, and a check to see if the required elapsed time has occurred.  If the time has not elapsed, the next state is the Wait state again.  The state machine can repeat any state as often as necessary.  So a 15 second delay could be implemented by going to a Wait state with a one second wait 15 times. Any error or new command will see a response in no more than one second.
    Lynn

Maybe you are looking for