Making an swing interface

hi
I want to make a display interface which loads and displays images and media files but I�m not sure what approach to take (don�t know were to start) should I have a single interface with all my fuction listed or do I need to break it up into classes e.g. image class /media class/ login class If anyone can point me in the right direction I would really appreciate it this is my third java program attempt so make I as simple as u can plz

Hi,
I am guessing you are a student, studying Software Engineering in some form?
Check Amazon for a good concise book on Software Patterns; take the time to find a good one as it will likely have a big influence, if you heed its advice, on the development of you programming skills at this early stage; Google and Forums are good but a reference book is better - where ekse do forum gurus (not me bythe way) get their knowledge from? ha.
As a starter, try to identify the main features and functionality of your application. Then modularise this functionality... packaging is the standard way to achieve this at code level. Jar files are the next step, but this is more on a component level.
Separate your GUI, logic and data where practical. Most of my applications and past projects have a 3-tier architecture generally arranged in this way:
1) You could start by developing some I/O (input/output) classes to handle reading writing the images and media files.
2) Then you can write the logic to process this data; marshal it into a form that you anticipate (or is plain necessary) to use in your GUI.
3) GUI's in my opinion is the longest part in implementing this kind of system - well to make a good one anyway. That aside, it is always helpful to have the data it will present ready and waiting to be presented - hence leaving it till last.
Java is great but these kinds of concepts should be learnt outside the scope of Java.
Where are you studying out of interest? If you are at university, perhaps ask a lecturer for a book recommendation.
Kind regards,
D

Similar Messages

  • PL/SQL and Java Swing interface

    Everybody in this forum knows that Oracle is the best database around
    with many functionalities, stability, performance, etc. We also know
    that PL/SQL is a great language to manipulate information directly
    in the database with many built in functions, OOP capability,
    transaction control, among other features. Today an application that
    manipulates information, which needs user interface, requires components
    to be developed using different technologies and normally running in
    different servers or machines. For example, the interface is done using
    a dynamic HTML generator like JSP, PHP, PL/SQL Web Toolkit, etc.
    This page is executed in an application server like Oracle iAS or
    Tomcat, just to name two, which in turn access a database like Oracle to
    build the HTML. Also rich clients like Java applets require an intermediate
    server to access the database (through servlets for example) although
    it is possible to access the database directly but with security issues.
    Another problem with this is that complexity increases a lot, many
    technologies, skills and places to maintain code which leads to a greater
    failure probability. Also, an application is constantly evolving, new
    calculations are added, new tables, changed columns. If you have an
    application with product code for example and you need to increase its
    size, you need to change it in the database, search for all occurrences
    of it in the middle-tier code and perhaps adjust interfaces. Normally
    there is no direct dependency among the tier components. On another
    issue, many application interfaces today are based on HTML which doesn't
    have interactive capabilities like rich-client interfaces. Although it
    is possible to simulate many GUI widgets with JavaScript and DHTML, it is
    far from the interactive level we can accomplish in rich clients like
    Java Swing, Flash MX, Win32, etc. HTML is also a "tag-based" language
    originally created to publish documents so even small pages require
    many bytes to be transmitted, far beyond of what we see on the screen.
    Even in fast networks you have a delay time to wait the page to be
    loaded. Another issue, the database is in general the central location
    for all kinds of data. Most applications relies on it for security,
    transaction and availability. My proposal is to use Oracle as the
    central location for interface, processing and data. With this approach
    we can create not only the data manipulation procedures in the database,
    but procedures that also control and manage user interfaces. Having
    a Oracle database as the central location for all components has many
    advantages:
    - Unique point of maintenance, backup and restore
    - Integrated database security
    - One language for everything, PL/SQL or Java (even both if desired)
    - Inherited database cache, transaction and processing optimizations
    - Direct access to the database dictionary
    - Application runs on Oracle which has support for many platforms.
    - Transparent use of parallel processing, clusters and future
    background technologies
    Regarding the interface, I already created a Java applet renderer
    which receives instructions from the database on how to create GUI
    objects and how to respond to events. The applet is only 8kb and can
    render any Swing or AWT object/event. The communication is done
    through HTTP or HTTPS using Oracles's MOD_PLSQL included in the Apache
    HTTP server which comes with the database or application server (iAS).
    I am also creating a database framework and APIs in PL/SQL to
    create and manipulate the client interface. The applet startup is
    very fast because it is very small, you don't need to download large
    classes with the client interface. Execution is done "on-demand"
    according to instructions received from the database. The instructions
    are very optimized in terms of network bandwidth and based on preliminary
    tests it can be up to 1/10 of a similar HTML screen. Less network usage
    means faster response and means that even low speed connections will
    have a good performance (a future development can be to use this in
    wireless devices like PDAs e even cell phones, just an idea for now).
    The applet can also be executed standalone by using Java Web Start.
    With this approach no business code, except the interface, is executed
    on the client. This means that alterations in the application are
    dynamically reflected in the client, no need to "re-download" the
    application. Events are transmitted when required only so network
    usage is minimized. It is also possible to establish triggering
    events to further reduce network usage. Since the protocol used is
    HTTP (which is stateless), the database framework I am creating will
    be responsible to maintain the state of connections, variables, locks
    and session information, so the developer don't need to worry about it.
    The framework will have many layers, from communication up to
    application so there will be pre-built functions to handle queries,
    pagination, lock, mail, log, etc. The final objective is to have a
    rich client application integrated into the database with minimum
    programming and maintenance requirements, not forgetting customization
    capabilities. Below is a very small example of what can de done. A
    desktop with two windows, each window with two fields, a button with an
    image to switch the values, and events to convert the typed text when
    leaving the field or double-clicking it. The "leave" event also has an
    optimization to only be triggered when the text changes. I am still
    developing the framework and adjusting the renderer but I think that all
    technical barriers were transposed by now. The framework is still in
    the early stages, my guess is that only 5% is done so far. As a future
    development even an IDE can be created so we have a graphical environment
    do develop applications. I am willing to share this with the PL/SQL
    community and listen to ideas and comments.
    Example:
    create or replace procedure demo1 (
    jre_version in varchar2 := '1.4.2_01',
    debug_info in varchar2 := 'false',
    compress_buffer in varchar2 := 'false',
    optimize_buffer in varchar2 := 'true'
    ) as
    begin
    interface.initialize('demo1_init','JGR Demo 1',jre_version,debug_info,compress_buffer,optimize_buffer);
    end;
    create or replace procedure demo1_init as
    begin
    toolkit.initialize;
    toolkit.create_icon('icon',interface.global_root_url||'img/switch.gif');
    toolkit.create_internal_frame('frame1','Frame 1',50,50,300,136);
    toolkit.create_label('frame1label1','frame1',10,10,50,20,'Field 1');
    toolkit.create_label('frame1label2','frame1',10,40,50,20,'Field 2');
    toolkit.create_text_field('frame1field1','frame1',50,10,230,20,'Field 1','Field 1',focus_event=>true,mouse_event=>true);
    toolkit.create_text_field('frame1field2','frame1',50,40,230,20,'Field 2','Field 2',focus_event=>true,mouse_event=>true);
    toolkit.set_text_field_event('frame1field1',toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,'FIELD 1','false');
    toolkit.set_text_field_event('frame1field2',toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,'FIELD 2','false');
    toolkit.set_text_field_event('frame1field1',toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,'field 1','false');
    toolkit.set_text_field_event('frame1field2',toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,'field 2','false');
    toolkit.create_button('button1','frame1',10,70,100,25,'Switch','Switch the values of "Field 1" and "Field 2"','S','icon');
    toolkit.set_button_event('button1',toolkit.action_performed_event,'demo1_switch_fields(''frame1field1'',''frame1field2'')','frame1field1:'||toolkit.get_text_method||',frame1field2:'||toolkit.get_text_method);
    toolkit.create_internal_frame('frame2','Frame 2',100,100,300,136);
    toolkit.create_label('frame2label1','frame2',10,10,50,20,'Field 1');
    toolkit.create_label('frame2label2','frame2',10,40,50,20,'Field 2');
    toolkit.create_text_field('frame2field1','frame2',50,10,230,20,'Field 1','Field 1',focus_event=>true,mouse_event=>true);
    toolkit.create_text_field('frame2field2','frame2',50,40,230,20,'Field 2','Field 2',focus_event=>true,mouse_event=>true);
    toolkit.set_text_field_event('frame2field1',toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,'FIELD 1','false');
    toolkit.set_text_field_event('frame2field2',toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,'FIELD 2','false');
    toolkit.set_text_field_event('frame2field1',toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,'field 1','false');
    toolkit.set_text_field_event('frame2field2',toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,'field 2','false');
    toolkit.create_button('button2','frame2',10,70,100,25,'Switch','Switch the values of "Field 1" and "Field 2"','S','icon');
    toolkit.set_button_event('button2',toolkit.action_performed_event,'demo1_switch_fields(''frame2field1'',''frame2field2'')','frame2field1:'||toolkit.get_text_method||',frame2field2:'||toolkit.get_text_method);
    end;
    create or replace procedure demo1_set_upper as
    begin
    toolkit.set_string_method(interface.global_object_name,toolkit.set_text_method,upper(interface.array_event_value(1)));
    toolkit.set_text_field_event(interface.global_object_name,toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,upper(interface.array_event_value(1)),'false');
    end;
    create or replace procedure demo1_set_lower as
    begin
    toolkit.set_string_method(interface.global_object_name,toolkit.set_text_method,lower(interface.array_event_value(1)));
    toolkit.set_text_field_event(interface.global_object_name,toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,lower(interface.array_event_value(1)),'false');
    end;
    create or replace procedure demo1_switch_fields (
    field1 in varchar2,
    field2 in varchar2
    ) as
    begin
    toolkit.set_string_method(field1,toolkit.set_text_method,interface.array_event_value(2));
    toolkit.set_string_method(field2,toolkit.set_text_method,interface.array_event_value(1));
    toolkit.set_text_field_event(field1,toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,upper(interface.array_event_value(2)),'false');
    toolkit.set_text_field_event(field2,toolkit.focus_lost_event,'demo1_set_upper',toolkit.get_text_method,upper(interface.array_event_value(1)),'false');
    toolkit.set_text_field_event(field1,toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,lower(interface.array_event_value(2)),'false');
    toolkit.set_text_field_event(field2,toolkit.mouse_double_clicked_event,'demo1_set_lower',toolkit.get_text_method,lower(interface.array_event_value(1)),'false');
    end;

    Is it sound like Oracle Portal?
    But you want to save a layer 9iAS.
    Basically, that was the WebDB.(Oracle changed the name to Portal when version 3.0)
    Over all, I agree with you.
    >>Having a Oracle database as the central location for all components has many
    >>advantages:
    >>
    >>- Unique point of maintenance, backup and restore
    >>- Integrated database security
    >>- One language for everything, PL/SQL or Java (even both if desired)
    >>- Inherited database cache, transaction and processing optimizations
    >>- Direct access to the database dictionary
    >>- Application runs on Oracle which has support for many platforms.
    >>- Transparent use of parallel processing, clusters and future
    >>background technologies
    I would like to build 'ZOPE' inside Oracle DB as a back-end
    Using Flash MX as front-end.
    Thomas Ku.

  • Plz help me in creating swing interface

    Hi,
    Iam new to swing.I have one Interface on swing.Now I want to add Jfilechooser object in my interface for selecting file from hard drive.So that I can upload this file through my servlet uploading programme.I want to set remote url also for saving the file.But I confused how I can do that.Plz guide me.
    I try to create one interface but iam sure it is not the correct way.Can u plz try with my codes. Below r my codes:
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import javax.swing.JMenuItem;
    import javax.swing.JCheckBoxMenuItem;
    import javax.swing.JMenu;
    import javax.swing.JFrame;
    import javax.swing.JMenuBar;
    import javax.swing.JTextArea;
    import javax.swing.JPanel;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JProgressBar;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.util.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.net.*;
    import javax.swing.accessibility;
    public class ActionDemo1 extends JFrame implements ActionListener
         JTextArea textArea,textArea1,textArea2,textArea3,textArea4,textArea5,textArea6,textArea7,
         textArea8,textArea9,textArea10,textArea11,textArea12,textArea13,textArea14,textArea15;
         private JProgressBar progressBar;          
         private JButton Button,Button1,Button2;     
         URL url;
         BufferedReader in;
         String str;
    public ActionDemo1()
                        setTitle("Upload Interface");                               
                        addWindowListener(new WindowAdapter()
                             public void windowClosing(WindowEvent e)
                                  System.exit(0);
         Container contentPane = getContentPane();          
         JMenuItem menuItem = null;
    JToolBar toolBar = new JToolBar();
         JToolBar toolBar1 = new JToolBar();     
         JToolBar toolBar2 = new JToolBar();
         JToolBar toolBar3 = new JToolBar();
         JToolBar toolBar4 = new JToolBar();
         JToolBar toolBar5 = new JToolBar();
         JToolBar toolBar6 = new JToolBar();
         JToolBar toolBar7 = new JToolBar();
         JToolBar toolBar8 = new JToolBar();
         JToolBar toolBar9 = new JToolBar();
         JToolBar toolBar10 = new JToolBar();
         JMenu FirstMenu = new JMenu("File");
    FirstMenu.setMnemonic(KeyEvent.VK_F);     
    textArea = new JTextArea(5, 20);
         textArea1 = new JTextArea(2, 15);     
         textArea2 = new JTextArea(2, 15);
         textArea3 = new JTextArea(2, 15);     
         textArea4 = new JTextArea(7, 15);
         textArea5 = new JTextArea(7, 15);     
         textArea6 = new JTextArea(7, 15);
         textArea7 = new JTextArea(7, 15);
         textArea8 = new JTextArea(2, 15);
         textArea9 = new JTextArea(7, 15);
         textArea10 = new JTextArea(2, 15);
         textArea11 = new JTextArea(7, 15);
         textArea12 = new JTextArea(2, 15);
         textArea13 = new JTextArea(7, 15);
         textArea14 = new JTextArea(2, 15);
         textArea15 = new JTextArea(7, 15);
         JScrollPane scrollPane = new JScrollPane(textArea);
         progressBar=new JProgressBar();
         progressBar.setStringPainted(true);     
    contentPane.setLayout(new GridLayout(2,3));
         JPanel panel1 = new JPanel();
         panel1.setLayout(new BorderLayout());
         panel1.setBackground(Color.blue);
         contentPane.add(panel1);
    panel1.add(BorderLayout.NORTH, toolBar);
         panel1.add(scrollPane, BorderLayout.CENTER);
         panel1.add(progressBar,BorderLayout.SOUTH);     
         JPanel panel2 = new JPanel();     
         JLabel statusBar= new JLabel();
         panel2.setLayout(new GridLayout(1,1));     
         panel2.setBackground(Color.gray);     
         contentPane.add(panel2);
         JPanel panel3 = new JPanel();
         panel3.setLayout(new GridLayout(1,1));     
         panel3.setBackground(Color.blue);
         panel2.add(panel3);
         JPanel panel7 = new JPanel();
         panel7.setLayout(new BorderLayout());     
         panel7.setBackground(Color.blue);
         panel7.add(textArea2, BorderLayout.NORTH);     
         panel7.add(BorderLayout.CENTER, toolBar2);
         panel7.add(BorderLayout.SOUTH, textArea4);
         panel3.add(panel7);
         JPanel panel8 = new JPanel();
         panel8.setLayout(new BorderLayout());     
         panel8.setBackground(Color.blue);
         panel8.add(textArea3, BorderLayout.NORTH);     
         panel8.add(BorderLayout.CENTER, toolBar3);
         panel8.add(BorderLayout.SOUTH, textArea5);
         panel3.add(panel8);
         JPanel panel5 = new JPanel();
         panel5.setLayout(new BorderLayout());
         panel5.add(textArea1, BorderLayout.NORTH);
         panel5.add(BorderLayout.CENTER, toolBar5);
         panel5.add(BorderLayout.SOUTH, textArea7);          
         panel5.setBackground(Color.blue);
         panel3.add(panel5);
         JPanel panel6 = new JPanel();
         panel6.setLayout(new BorderLayout());
         panel6.add(toolBar1, BorderLayout.NORTH);          
         panel6.setBackground(Color.blue);
         panel6.setSize(new Dimension(5,5));
         panel6.add(BorderLayout.CENTER, toolBar4);
         panel6.add(BorderLayout.SOUTH, textArea6);
         panel3.add(panel6);
         JPanel panel4 = new JPanel();
         panel4.setLayout(new GridLayout(1,1));
         panel4.setBackground(Color.blue);     
         panel2.add(panel4);
         JPanel panel9 = new JPanel();
         panel9.setLayout(new BorderLayout());     
         panel9.setBackground(Color.blue);
         panel9.add(textArea8, BorderLayout.NORTH);     
         panel9.add(BorderLayout.CENTER, toolBar6);
         panel9.add(BorderLayout.SOUTH, textArea9);
         panel4.add(panel9);
         JPanel panel10 = new JPanel();
         panel10.setLayout(new BorderLayout());     
         panel10.setBackground(Color.blue);
         panel10.add(textArea10, BorderLayout.NORTH);     
         panel10.add(BorderLayout.CENTER, toolBar7);
         panel10.add(BorderLayout.SOUTH, textArea11);
         panel4.add(panel10);
         JPanel panel11 = new JPanel();
         panel11.setLayout(new BorderLayout());
         panel11.add(textArea12, BorderLayout.NORTH);
         panel11.add(BorderLayout.CENTER, toolBar8);
         panel11.add(BorderLayout.SOUTH, textArea13);          
         panel11.setBackground(Color.blue);
         panel4.add(panel11);
         JPanel panel12 = new JPanel();
         panel12.setLayout(new BorderLayout());
         panel12.add(toolBar9, BorderLayout.NORTH);          
         panel12.setBackground(Color.blue);
         panel12.setSize(new Dimension(5,5));
         panel12.add(BorderLayout.CENTER, toolBar10);
         panel12.add(BorderLayout.SOUTH, textArea15);
         panel4.add(panel12);
         //contentPane.setMaximumSize(new Dimension(600, 400));
         /*contentPane.setLayout(new BorderLayout());
         contentPane.setPreferredSize(new Dimension(400, 150));
         contentPane.add(toolBar, BorderLayout.NORTH);     
    statusBar = new JLabel(" ");     
         contentPane.add(scrollPane, BorderLayout.CENTER);
         setContentPane(contentPane);*/     
         JMenuBar mb = new JMenuBar();
         setJMenuBar(mb);
    mb.add(FirstMenu);     
    menuItem = new JMenuItem("Quick connect", KeyEvent.VK_Q);
    FirstMenu.add(menuItem);
         JMenu SecondMenu = new JMenu("Edit");
         SecondMenu.setMnemonic(KeyEvent.VK_E);     
    menuItem = new JMenuItem("Suspend", KeyEvent.VK_S);
    SecondMenu.add(menuItem);
    mb.add(SecondMenu);
    JMenu ThirdMenu = new JMenu("Compress");
         ThirdMenu.setMnemonic(KeyEvent.VK_C);     
    menuItem = new JMenuItem("By Percentage", KeyEvent.VK_B);
    ThirdMenu.add(menuItem);
    mb.add(ThirdMenu);
    JMenu FourthMenu = new JMenu("Help");
         FourthMenu.setMnemonic(KeyEvent.VK_H);     
    menuItem = new JMenuItem("Help", KeyEvent.VK_B);
    FourthMenu.add(menuItem);
    mb.add(FourthMenu);
    ImageIcon QuickConnect=new ImageIcon("images/Q_connect.gif");
    JButton button=new JButton(QuickConnect);
    button.setActionCommand("QuickConnect");
    button.setToolTipText("Quick Connect");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Reconnect=new ImageIcon("images/Reconnect.gif");
    button=new JButton(Reconnect);
    button.setActionCommand("Reconnect");
    button.setToolTipText("Reconnect");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Disconnect=new ImageIcon("images/Disconnect.gif");
    button=new JButton(Disconnect);
    button.setActionCommand("Disconnect");
    button.setToolTipText("Disconnect");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Upload=new ImageIcon("images/Upload.gif");
    Button=new JButton(Upload);
    Button.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    String strCommand=ae.getActionCommand();
    if(str.equals("Upload"))
    /* this is where you write the code to call that servlet.
    control reaches this point when the button is pressed */
    try{
    // you communicate with the servlet here
    url = new URL("http://127.0.0.1:7001/servletUpload");
    in = new BufferedReader(new InputStreamReader(url.openStream()));
    str = in.readLine();
    in.close();
    }//end try
    catch (Exception e1){}
    toolBar.add(Button);
    ImageIcon Suspend=new ImageIcon("images/Suspend.gif");
    Button1=new JButton(Suspend);
    //Button1.setActionCommand("Suspend");
    Button1.setToolTipText("Suspend");
    Button1.addActionListener(this);
    toolBar.add(Button1);
    ImageIcon Refresh=new ImageIcon("images/Refresh.gif");
    button=new JButton(Refresh);
    button.setActionCommand("Refresh");
    button.setToolTipText("Refresh");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon DeleteItem=new ImageIcon("images/DeleteItem.gif");
    button=new JButton(DeleteItem);
    button.setActionCommand("DeleteItem");
    button.setToolTipText("DeleteItem");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Resume=new ImageIcon("images/Resume.gif");
    Button2=new JButton(Resume);
    //button.setActionCommand("Resume");
    Button2.setToolTipText("Resume");
    Button2.addActionListener(this);
    toolBar.add(Button2);
    ImageIcon FilePriority=new ImageIcon("images/FilePriority.gif");
    button=new JButton(FilePriority);
    button.setActionCommand("FilePriority");
    button.setToolTipText("FilePriority");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon View=new ImageIcon("images/View.gif");
    button=new JButton(View);
    button.setActionCommand("View");
    button.setToolTipText("View");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Rename=new ImageIcon("images/Rename.gif");
    button=new JButton(Rename);
    button.setActionCommand("Rename");
    button.setToolTipText("Rename");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Scrolling=new ImageIcon("images/left.gif");
    button=new JButton(Scrolling);
    button.setActionCommand("Scrolling");
    button.setToolTipText("Scrolling");
    button.addActionListener(this);
    toolBar1.add(button);
    ImageIcon UScrolling=new ImageIcon("images/right.gif");
    button=new JButton( UScrolling);
    button.setActionCommand(" UScrolling");
    button.setToolTipText("UScrolling");
    button.addActionListener(this);
    toolBar1.add(button);
    ImageIcon Name=new ImageIcon("images/Name.gif");
    button=new JButton( Name);
    button.setActionCommand("Name");
    button.setToolTipText("Name");
    button.addActionListener(this);
    toolBar2.add(button);
    ImageIcon Date=new ImageIcon("images/Date.gif");
    button=new JButton( Date);
    button.setActionCommand("Date");
    button.setToolTipText("Date");
    button.addActionListener(this);
    toolBar3.add(button);
    ImageIcon Time=new ImageIcon("images/Time.gif");
    button=new JButton( Time);
    button.setActionCommand("Time");
    button.setToolTipText("Time");
    button.addActionListener(this);
    toolBar4.add(button);
    ImageIcon Size=new ImageIcon("images/Size.gif");
    button=new JButton(Size);
    button.setActionCommand("Size");
    button.setToolTipText("Size");
    button.addActionListener(this);
    toolBar5.add(button);
    ImageIcon TScrolling=new ImageIcon("images/left.gif");
    button=new JButton(TScrolling);
    button.setActionCommand("TScrolling");
    button.setToolTipText("TScrolling");
    button.addActionListener(this);
    toolBar9.add(button);
    ImageIcon DScrolling=new ImageIcon("images/right.gif");
    button=new JButton( DScrolling);
    button.setActionCommand(" DScrolling");
    button.setToolTipText("DScrolling");
    button.addActionListener(this);
    toolBar9.add(button);
    ImageIcon Name1=new ImageIcon("images/Name.gif");
    button=new JButton( Name1);
    button.setActionCommand("Name1");
    button.setToolTipText("Name1");
    button.addActionListener(this);
    toolBar6.add(button);
    ImageIcon Date1=new ImageIcon("images/Date.gif");
    button=new JButton( Date1);
    button.setActionCommand("Date1");
    button.setToolTipText("Date1");
    button.addActionListener(this);
    toolBar7.add(button);
    ImageIcon Time1=new ImageIcon("images/Time.gif");
    button=new JButton( Time1);
    button.setActionCommand("Time1");
    button.setToolTipText("Time1");
    button.addActionListener(this);
    toolBar10.add(button);
    ImageIcon Size1=new ImageIcon("images/Size.gif");
    button=new JButton(Size1);
    button.setActionCommand("Size1");
    button.setToolTipText("Size1");
    button.addActionListener(this);
    toolBar8.add(button);
    public void actionPerformed(ActionEvent e)
    textArea.setText(e.getActionCommand());
    public static void main(String[] args) {
    ActionDemo1 frame = new ActionDemo1();
    frame.pack();
    frame.setSize(new Dimension(650, 400));
    frame.setVisible(true);
    Regards
    Bikash

    You may find this suggestion useless, but I thnk you should seriously consider tossing your IDE in the trash and getting a good text editor and hand coding Swing until you understand how Swing components work.
    Take shortcuts when you understand where they will lead. You will find that hand coding really leads to a deeper understanding of any programming language.
    While you're at it, why don't you consider whether you really need eleven (!) toolbars in your GUI. A GUI generally needs only one toolbar -- save some for later.

  • How to build those slick Swing interfaces?

    Hello,
    I know how to write Swing applications, but cannot seem to create those slick, polished GUIs implemented in commercial applications, such as Borland JBuilder.
    Is there a resource from where I can get samples of desktop applications built using Java Swing which have a professional look and contain a variety of protocols? I am trying to take my Swing skills to the next level.
    Thanks,
    Nadeem

    I have found over the years, that the real slick inerface designs have very little to do with your ability in a development too, but usually consists, to a very large degree, on your imagination, artistic ability, depth perception, and ability to visulize.
    If you can come up with a formula for it let me know, I've very usable, but yet mechanical or plain interfaces that I develop in all of the languages--even if they have GUI/WUSIWUG development interfaces with them.

  • Optimization problem... swing interface

    I have a swing application, and i want to execute a method that makes many calculations and takes much time. When i call the method with the swing dialog open, it takes about 10x more time then if it was run from a console application, because the dialog remains handling events and all. How do i pause the event handling of the interface, or what should be the aproach to this situation?

    You might want to take a look at invokeAndWait and invokeLater of the SwingUtilities class:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/SwingUtilities.html

  • Making airport default interface while having ethernet plugged in

    Hello,
    I want to have my internet activity going through airport while using Wirewhark to sniff my ethernet interface. Is it possible? Everytime I plug the ethernet cable in, my default network interface becomes the ethernet adapter, and there is no connectivity there, only packets being sent to be sniffed, so I loose my email access and so on.
    Thanks,

    Go to System Preferences, Network, and arrange the network device list so that AirPort is above Ethernet in the list (you drag and drop them). I'm not in front of my mac right now so I cant tell you the exact clicking sequence, but this is very doable in the Network Control Panel.
    Good luck!

  • Scope and Objectives of making java swing scientific calculator

    I am going to write code for java swing scientific calculator..... can any body help me to write scope and objectives of this project.... please please :-(

    If this is for school work, then defining the scope is part of the problem. The only advice I will give you is that you only need to implement what the assignment specifies. It is probably intentionally vague so you can bite off way too much and not finish -- failure should teach you something too.
    I had just such an assignment in my software engineering class in college -- create a cross compiler from X to Y where X and Y where known instruction sets. That was the entire assignment -- plus the instruction sets for X and Y. My team looked at the allotted time and resources availabe and decided to do a minimal implementation.
    We where the only team to complete the assignment and all recieved A's because we accurately implemented the required solution and were able to evaluate the real problem--resource allotment--accurately.
    Each other team tried to add "extras" that would "guarantee" them an A grade. In actuallity it was just a lot more work than they could do though and it hurt them in the long run--No matter how good the work was to the point they had at the end of the semester, each student in the other teams only recieved a B or less grade in the class due to failure on that project. Resource allocation and planning--only you can do that for your team/project.

  • Making a USB interface

    Something I always wanted to do is to be able to design some hardware that would send information into a computer and communicate with some software that the user could interact with. Here are some examples: I have different hardware with USB inputs such as a biofeedback device, a sound level meter, etc. Or, if I designed a circuit that sent and received information to a USB output which could be plugged into a computer. It would be great to be able to write a program that gets and sends information to these devices. But, I just do not know where to start. I was wondering if one of you could point me in the direction of understanding the process. Does it involve writing a driver? If so, what is involved? etc.
    Here is concretely what I am looking to do now.
    I have an exercise bike that has an eight pin input from the bike into a circuit board which connects to a screen. I would like to disconnect the screen and communicate with the bike through my laptop running Mac OS X. I figure it must be possible to have the eight pin input connect to a USB computer input that would connect to a computer. I imagine, if you understood how Mac OS X works at a fundamental level, you could then write a program that would then use the input from the bike (through the USB input).
    Somebody must know how to do this because every device that hooks into a computer must do this. I would just like to know the basics of how to get this to work at the most simple level. Any help would be greatly appreciated.

    Here is concretely what I am looking to do now.
    I have an exercise bike that has an eight pin input
    from the bike into a circuit board which connects to
    a screen. I would like to disconnect the screen and
    communicate with the bike through my laptop running
    Mac OS X.
    Forget about USB and OSX and programming etc for now.. the first thing you will need to do is work out what each of those wires are used for. Are they connected to sensors or another circuit? Do they drive the screen, or does the screen drive them? Do they need power? What voltage? etc. If you can't do this.. then there isn't much point continuing any further until you can. If you aren't already handy with a multimeter and a soldering iron, then you might want to try interfacing the computer with something a little less complicated to start with, or find someone who is experienced to help you.
    How to talk to/program for a custom USB device is going to be the last thing you want to deal with, not to mention requires many years of system level programming experience. Something I am assuming you don't have by the way you asked the question (no offence intended).
    That's not to say don't attempt it.. on the contrary, it sounds like a cool idea, however it's not going to be easy. For the computer interface part I would probably be looking for an already supported, cheap, input device that can be repurposed to suit, such as a USB gamepad controller, which have numerous digital and analogue inputs, not to mention readily available example source code from apple on how to talk to it.
    Seeya...Q

  • Need an example of server / client program with swing interface

    Hi!
    After a lot of trying i still haven't managed to create a server client program using swing components ...
    can someone write a mini application to demonstrate how this can be done?
    i would like to have a frame with a button a texField for input and a textAread for the output
    What i have in mind is the following ..
    say im the server
    i write something in the textField and then i press the button
    then the information written in the textFiled is passed to the client who shows it in his textArea
    The same thing goes on with the client (he can write something in his own textField and when he presses the button the info is passed at the
    server who puts it in his textArea) and vice versa.
    i have written many classes that trying unsuccessfully to do that ... below i show my last attempt ...
    I would appreciate if you could write a small application which it could to this.
    The whole idea is to create a turn based game ( i have implemented the game engine and graphics and i try to add the internet function)
    Here is the code ...( i would appreciate if you write a new code instead of trying to correct mine ( which i think it's impossible) in order to use it as a general example)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    @SuppressWarnings("serial")
    *  In order to have a more gereral program instead of passing strings between the server
    *  and the client a pass an MyObjext object.  The MyObject class has an integer and a String
    *  (which is always the same) field . At the textField i write an integer number and i
    *  make a new MyObject which i want to pass to the server or the client and vice versa.
    *  The textArea shows the integer value of the MyObject which was passed from the server /client
    public class MyUserInterface extends JFrame {
         MyObject returnObject;
         JTextField myTextField;
         JTextArea te ;
         ClientGame cg;
         ServerGame sg;
          * used to determine if the current instance is running as a client or host
         boolean isHost;
         //The constructor of the client
         public MyUserInterface(ClientGame cg){
              this("Client");
              this.cg = cg;
              isHost = false;
         //The constructor of the server
         public MyUserInterface(ServerGame sg){
              this("Server");
              this.sg = sg;
              isHost = true;
         //The general constructor used both by client and server ..
         // it initializes the GUi components and add an actionListenr to the button
         public MyUserInterface(String str) {
              super(str);
              myTextField = new JTextField(2);
              te = new JTextArea();
              te.setPreferredSize(new Dimension(100,100));
              JButton okButton = new JButton("Ok");
              okButton.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e) {
                        try{
                             int a = Integer.parseInt(MyUserInterface.this.myTextField.getText());
                             System.out.println(a);   //used to control the flow of the program
                                  MyUserInterface.this.returnObject = new MyObject(a);
                             //sends the data
                             sendData();
                             //waiting for response...
                             getData();
                             catch(Exception ex){System.out.println("Error in the UI action command" +
                                                                ex.printStackTrace();}
              JPanel panel =  new JPanel(new FlowLayout());
              panel.add(okButton);
              panel.add(myTextField);
              panel.add(te);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              getContentPane().add(panel);
              pack();
              setVisible(true);
         protected MyObject getReturnObject() {
              return returnObject;
         public void sendData(){
              new Thread(new Runnable() {
                   @Override
                   public void run() { 
                        if (!isHost)cg.sentData(returnObject);    //using the Servers out and in methods
                        else sg.sentData(returnObject);                    //using the Clients out and in methods
                        System.out.println("data sending");
         public MyObject getData(){
              MyObject obj;
              System.out.println("Retrieveing Data");
              if (!isHost)obj = (MyObject)cg.getData();
              else obj = (MyObject)sg.getData();
              System.out.println(" data retrieved  = "+ obj.getInt());  //just to control how the code flows
              te.setText(obj.getInt()+"");       
              return obj;
         public static void main(String[] args) {
              *Initiating the Server
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        ServerGame sg = new ServerGame();
                        new MyUserInterface(sg);
              }).start();     
               * Initiating the Client
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        ClientGame cg = new ClientGame("192.168.178.21");   //<----in case you run my code
                                                                          //..don't forget to change to your
                        new MyUserInterface(cg);                              //ip
              }).start();
    import java.io.*;
    import java.net.*;
    public class ClientGame {
         String ipAddress;
         Socket clientSocket = null;
        ObjectOutputStream out = null;
        ObjectInputStream in = null;
         public ClientGame(String ipAddress) {
              this.ipAddress = ipAddress;
              try {
                   System.out.println("Connecting To Host");
                 clientSocket = new Socket(InetAddress.getByName(ipAddress),4444);
                System.out.println("Host Found ...Io initializaton");
                out = new ObjectOutputStream(clientSocket.getOutputStream());
                in = new ObjectInputStream(clientSocket.getInputStream());
            } catch (UnknownHostException e) {
                System.err.println("Don't know about host: taranis.");
                System.exit(1);
            } catch (IOException e) {
                System.err.println("Couldn't get I/O for the connection to: taranis.");
                System.exit(1);
         public Object getData(){
              Object fromServer = null ;
              do{
                 try {
                      fromServer = in.readObject();
                 catch(ClassNotFoundException ex){}
                  catch(IOException e){}
              }while(fromServer==null);
              return fromServer;        
         public void sentData(final Object obj){
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        try{
                             out.writeObject(obj);
                        catch(IOException e){}
              }).start();
         public void terminateConnection(){
              try{
                   out.close();
                   in.close();
                   clientSocket.close();
              catch (IOException e){}
    public class ServerGame {
         ServerSocket serverSocket;
         Socket clientSocket;
         ObjectOutputStream out = null;
        ObjectInputStream in = null;
         public ServerGame() {
              try{
                   serverSocket = new ServerSocket(4444);
                   clientSocket = serverSocket.accept();
                   out =  new ObjectOutputStream(clientSocket.getOutputStream());
                in = new ObjectInputStream(clientSocket.getInputStream());
              catch(IOException e){System.out.println("IOException in ServerGame");}
         public Object getData(){
              Object fromClient = null ;
              do{
                 try {
                      fromClient = in.readObject();
                 catch(ClassNotFoundException ex){}
                  catch(IOException e){}
              }while(fromClient==null);
             return fromClient;        
         public void sentData(final Object obj){
              new Thread(new Runnable() {
                   @Override
                   public void run() {
                        try{
                   out.writeObject(obj);
              catch(IOException e){}
              }).start();
         public void terminateConnection(){
              try{
                   out.close();
                   in.close();
                   clientSocket.close();
                   serverSocket.close();
              catch (IOException e){}
         public static void main(String[] args) {
              new ServerGame();
    import java.io.Serializable;
    * this is a test object
    * it has a String field and a value
    *  The string is always the same but the integer value is defined in the constructor
    public class MyObject implements Serializable{
         private static final long serialVersionUID = 1L;
         String str;
         int myInt;
         MyObject(int a){
              str = "A String";
              myInt = a;
         public int getInt(){
              return myInt;
    }

    Pitelk wrote:
    I believe that a good code example can teach you things ;that you would need many days of searching; in no timeSo lets write one small example.. Ill help a little, but you do most of the work.
    jverd approach is deffenetly the way to go.
    jverd wrote:
    * Write a very small, simple Swing program with an input area, an output area, and a button. When you click the button, what's in the input area gets copied over to the output area.This part is partially done.
    * Write a very small, simple client/server program without Swing. It should just send a couple of hardcoded messages back and forth.And this part is for you(Pitelk) to continue on. I cannot say that this is the best way. or that its good in any way. I do however like to write my client/server programs like this. And perhaps, and hopefully, Ill learn something new from this as well.
    This is how far I got in about 10-20min..
    package client;
    * To be added;
    * A connect method. That connects the client to the server and
    * opens up both the receive and transmit streams. After doing that
    * the an instance of the ServerListener class should be made.
    * Also an disconnect method could be usable. But thats a later part.
    public class TestClass1 {
    package utils;
    import java.io.ObjectInputStream;
    import client.TestClass1;
    * This class is meant to be listening to all responses given from
    * the server to the client. After a have received data from the
    * server. It should be forwarded to the client, in this case
    * TestClass1.
    public class ServerListener implements Runnable {
         public ServerListener(ObjectInputStream in, TestClass1 tc) {
         @Override
         public void run() {
              while(true) {
    package server;
    import java.io.ObjectOutputStream;
    import java.net.Socket;
    import java.util.ArrayList;
    import java.util.List;
    * This class should handle all data sent to the server from the clients.
    class Server implements Runnable {
         private static List<ObjectOutputStream> outStreams = new ArrayList<ObjectOutputStream>();
         private Socket client = null;
         public Server(Socket client) {
              this.client = client;
         @Override
         public void run() {
              while(true) {
    * The meaning of this class is to listen for clients trying to connect
    * to the server. Once connection is achieved a new thread for that client
    * should be made to listen for data sent by the client to the server.
    public class ChatServer implements Runnable {
         @Override
         public void run() {
              while(true) {
    package utils;
    import java.io.Serializable;
    @SuppressWarnings("serial")
    public class MyObject implements Serializable {
         private String mssg;
         private String clientID;
         private String clientName;
         public MyObject(String mssg, String clientID, String clientName) {
              this.mssg = mssg;
              this.clientID = clientID;
              this.clientName = clientName;
         //Generate getters and setters..
    }Continue on this, and when you get into problems etc post them. Also show with a small regular basis how far you have gotten with each class or it might be seen as you have lost intresst and then this thread is dead.
    EDIT: I should probably also say that Im not more than a java novice, at the verry most. So I cannot guarantee that I alone will be able to solve all the problems that might occure during this. But Im gonna try and help with the future problems that may(most likely will) occure atleast(Trying to reserve my self incase of misserable failiure from me in this attempt).
    Edited by: prigas on Jul 7, 2008 1:47 AM

  • Java Swing Applets in Mac Os

    hi there,
    I am a student at the University of Portsmouth in the UK in my third and last year. I am doing my dissertation as a game using applets for a client at the university of which there consits four prototypes. One of the main specification points is that it should work on an apple mac, therefore I am using Swing applets. however with my first prototype it works fine on windows in windows Explorer, firefox and Netscape but i cant get it to work on Mac os 9 or X even with the latest version of java installed on the machine. Can anyone tell me why this is so, I would be very gratefull.
    As I cant post the whole applet here as a file download I will just put some code snippets of the main program classes.
    Applet ------------------------------
    * Class JugglingBalls - A sub class of JApplet that combines the GameInterface and GamePanel into a single application
    * @author (Liam Morren)
    * @version (v1.0)
    import java.awt.*;
    import javax.swing.*;
    public class JugglingBalls extends JApplet
        // instance variables -----------------------------------------------------------------------------------------------------------------------------------
        private GamePanel gamePanel; // The game panel including game and render loop
        private GameInterface gameInterface; // The swing interface to modify the game scene components
        // JApplet methods -------------------------------------------------------------------------------------------------------------------------------------
         * Called by the browser or applet viewer to inform this JApplet that it
         * has been loaded into the system. It is always called before the first
         * time that the start method is called.
        public void init()
            gamePanel = new GamePanel();
            gameInterface = new GameInterface(gamePanel.getGameScene());
            Container content = getContentPane(); // The container for components in the applet
            setLayout(new BoxLayout(content, BoxLayout.X_AXIS));
            content.add(gamePanel);
            content.add(gameInterface);
         * Returns information about this applet.
         * An applet should override this method to return a String containing
         * information about the author, version, and copyright of the JApplet.
         * @return a String representation of information about this JApplet
        public String getAppletInfo()
            // provide information about the applet
            return "Title: JugglingBalls  \nAuthor: Liam Morren  \nA simple application showing balls juggling in the air.";
    Interface -------------------------------------
    * Class GameInterface - Lets you manipulate the game components using swing components
    * @author (Liam Morren)
    * @version (v1.0)
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class GameInterface extends JPanel
        // instance variables -------------------------------------------------------------------------------------------------------------------------------------
        private GameScene gameScene; // Reference to the game scene
        private JTabbedPane gameTabs; // Tabs for Game, Balls and Background
        // Scene panel
        JButton pause, start, reset; // Buttons
        // Balls panel
        JRadioButton redBall, greenBall, blueBall, archBall, figureOfEightBall; // Radio buttons
        JCheckBox canSplit; // Check box
        JComboBox setAllPaths, setAllTypes, newBall, selectBall; // Drop down boxes
        JButton deleteBall; // Button
        Ball currentBall; // Current ball being changed
        // Background panel
        JRadioButton black, white, red, green, blue, hide, show, stop, move, arch, figureOfEight; // Radio buttons
        // Constructors -------------------------------------------------------------------------------------------------------------------------------------------
         * Constructor for objects of class GameInterface
        public GameInterface(GameScene gameSceneIn)
            gameScene = gameSceneIn; // Reference to the game scene
            gameTabs = new JTabbedPane(); // JTabbedPane to hold different toolbars
            gameTabs.setPreferredSize(new Dimension(200, 494)); // Set the preffered size for the tabbed pane
            currentBall = gameScene.getBall(0); // First ball
            // Add the panels to the tabbed pane
            gameTabs.addTab("Scene", makeScenePanel());
            gameTabs.addTab("Balls", makeBallsPanel());
            gameTabs.addTab("Background", makeBackgroundPanel());
            add(gameTabs); // Add the tab to the game interface panel
            setPreferredSize(new Dimension(200, 200));
        // Other methods ------------------------------------------------------------------------------------------------------------------------------------------
         * makeScenePanel
         * @return JPanel - The scene panel with buttons added
        private JPanel makeScenePanel()
            // Make scene panel
            JPanel scenePanel = new JPanel();
            scenePanel.setLayout(new BoxLayout(scenePanel, BoxLayout.Y_AXIS)); // Change layout
            pause = new JButton("Pause"); // Make buttons
            start = new JButton("Start");
            reset = new JButton("Reset");
            // Add button actions
            pause.addActionListener(new ActionListener() // Add button listener to pause button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    gameScene.setPaused(true); // Pause game
            start.addActionListener(new ActionListener() // Add button listener to start button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    gameScene.setPaused(false); // Unpause game
            reset.addActionListener(new ActionListener() // Add button listener to reset button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    gameScene.reset(); // Reset game
                    updateSelectBallComboBox();
                    changeSelectedBall(0);
            scenePanel.add(pause); // Add buttons to scene panel
            scenePanel.add(start);
            scenePanel.add(reset);
            return scenePanel;
         * makeBackgroundPanel
         * @return JPanel - The background panel with buttons added
        private JPanel makeBackgroundPanel()
            // Make scene panel
            JPanel backgroundPanel = new JPanel();
            backgroundPanel.setLayout(new GridLayout(5, 1, 2, 2)); // Change layout
            // Make buttons
            // background colour buttons
            JPanel backgroundcolour = new JPanel(); // Change backgroundcolour panel
            backgroundcolour.setBorder(BorderFactory.createLineBorder(Color.black));
            black = new JRadioButton("Black"); // Radio buttons to change colour
            white = new JRadioButton("white");
            black.setSelected(true); // Set black as already selected
            ButtonGroup backColourGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
            backColourGroup.add(black); // Add buttons to group
            backColourGroup.add(white);
            backgroundcolour.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
            backgroundcolour.add(new JLabel("Background colour")); // Add label
            backgroundcolour.add(black); // Add buttons to colours panel
            backgroundcolour.add(white);
            // Add radio button actions
            black.addActionListener(new ActionListener() // Add button listener to black button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    gameScene.setBackgroundColour(false); // Background colour = black
            white.addActionListener(new ActionListener() // Add button listener to white button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    gameScene.setBackgroundColour(true); // Background colour = white
            // colour buttons
            JPanel colours = new JPanel(); // Change colours panel
            colours.setBorder(BorderFactory.createLineBorder(Color.black));
            red = new JRadioButton("Red"); // Radio buttons to change colour
            green = new JRadioButton("Green");
            green.setSelected(true); // Set green as already selected
            blue = new JRadioButton("Blue");
            ButtonGroup colourGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
            colourGroup.add(red); // Add buttons to group
            colourGroup.add(green);
            colourGroup.add(blue);
            colours.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
            colours.add(new JLabel("Change colours")); // Add label
            colours.add(red); // Add buttons to colours panel
            colours.add(green);
            colours.add(blue);
            // Add radio button actions
            red.addActionListener(new ActionListener() // Add button listener to red button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    if (gameScene.getBackgroundEffect().getColour() != 0)
                        gameScene.getBackgroundEffect().setColour(0); // Background effect colour = red
            green.addActionListener(new ActionListener() // Add button listener to green button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    if (gameScene.getBackgroundEffect().getColour() != 1)
                        gameScene.getBackgroundEffect().setColour(1); // Background effect colour = green
            blue.addActionListener(new ActionListener() // Add button listener to blue button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    if (gameScene.getBackgroundEffect().getColour() != 2)
                        gameScene.getBackgroundEffect().setColour(2); // Background effect colour = blue
            // hide buttons
            JPanel hideShow = new JPanel(); // Change hideShow panel
            hideShow.setBorder(BorderFactory.createLineBorder(Color.black));
            hide = new JRadioButton("Hide"); // Radio buttons to hide show
            show = new JRadioButton("Show");
            show.setSelected(true); // Set show as already selected
            ButtonGroup hideShowGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
            hideShowGroup.add(hide); // Add buttons to group
            hideShowGroup.add(show);
            hideShow.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
            hideShow.add(new JLabel("Hide / Show")); // Add label
            hideShow.add(hide); // Add buttons to hideShow panel
            hideShow.add(show);
            // Add radio button actions
            hide.addActionListener(new ActionListener() // Add button listener to hide button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                        gameScene.getBackgroundEffect().hide(); // Hide
            show.addActionListener(new ActionListener() // Add button listener to show button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                        gameScene.getBackgroundEffect().unHide(); // Unhide
            // stopMove buttons
            JPanel stopMove = new JPanel(); // Change StopMove panel
            stopMove.setBorder(BorderFactory.createLineBorder(Color.black));
            stop = new JRadioButton("Stop"); // Radio buttons to stop move
            move = new JRadioButton("Move");
            stop.setSelected(true); // Set stop as already selected
            ButtonGroup stopMoveGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
            stopMoveGroup.add(stop); // Add buttons to group
            stopMoveGroup.add(move);
            stopMove.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
            stopMove.add(new JLabel("Stop / Move")); // Add label
            stopMove.add(stop); // Add buttons to stopMove panel
            stopMove.add(move);
            // Add radio button actions
            stop.addActionListener(new ActionListener() // Add button listener to stop button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                        gameScene.getBackgroundEffect().setMove(false); // stop
            move.addActionListener(new ActionListener() // Add button listener to move button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                        gameScene.getBackgroundEffect().setMove(true); // move
            // changePath buttons
            JPanel changePath = new JPanel(); // Change changePath panel
            changePath.setBorder(BorderFactory.createLineBorder(Color.black));
            arch = new JRadioButton("Arch"); // Radio buttons to change path
            figureOfEight = new JRadioButton("Figure of eight");
            arch.setSelected(true); // Set stop as already selected
            ButtonGroup changePathGroup = new ButtonGroup(); // Group buttons so only one can be pressed at a time
            changePathGroup.add(arch); // Add buttons to group
            changePathGroup.add(figureOfEight);
            changePath.setLayout(new GridLayout(2, 2, 0, 0)); // Change layout
            changePath.add(new JLabel("Change Path")); // Add label
            changePath.add(arch); // Add buttons to changePath panel
            changePath.add(figureOfEight);
            // Add radio button actions
            arch.addActionListener(new ActionListener() // Add button listener to arch button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                        gameScene.getBackgroundEffect().setPath(new Arch()); // Arch
            figureOfEight.addActionListener(new ActionListener() // Add button listener to figureOfEight button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                        gameScene.getBackgroundEffect().setPath(new FigureOfEight()); // Figure of eight
            // Add components to background panel
            backgroundPanel.add(backgroundcolour);
            backgroundPanel.add(colours);
            backgroundPanel.add(hideShow);
            backgroundPanel.add(stopMove);
            backgroundPanel.add(changePath);
            return backgroundPanel;
         * makeBallsPanel
         * @return JPanel - The ball panel with buttons added
        private JPanel makeBallsPanel()
            // Make balls panel
            JPanel ballsPanel = new JPanel();
            ballsPanel.setLayout(new BoxLayout(ballsPanel, BoxLayout.Y_AXIS)); // Change layout
            // Make buttons
            // set all drop down boxes
            JPanel setAll = new JPanel(); // Set all panel
            setAll.setBorder(BorderFactory.createLineBorder(Color.black));
            String[] setAllPathsChoices = {"Arch", "Figure of eight"}; // Selections for set all paths
            setAllPaths = new JComboBox(setAllPathsChoices); // Add selections to combo box
            String[] setAllTypesChoices = {"Primary ball", "Pastel ball", "3D ball", "Image ball"}; // Selections for set all types
            setAllTypes = new JComboBox(setAllTypesChoices); // Add selections to combo box
            setAll.add(new JLabel("Set all paths")); // Add combo boxes to set all panel
            setAll.add(setAllPaths);
            setAll.add(new JLabel("Set all types"));
            setAll.add(setAllTypes);
            // Add combo box actions
            setAllPaths.addActionListener(new ActionListener() // Add selection listener to set all paths combo box
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    if (setAllPaths.getSelectedItem() == "Arch")
                        gameScene.setAllPathsArch();
                    else
                        gameScene.setAllPathsFigureOfEight();
            setAllTypes.addActionListener(new ActionListener() // Add selection listener to set all types combo box
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    if (setAllTypes.getSelectedItem() == "Primary ball")
                        gameScene.setAllTypesPrimaryBall();
                    else if (setAllTypes.getSelectedItem() == "Pastel ball")
                        gameScene.setAllTypesPastelBall();
                    else if (setAllTypes.getSelectedItem() == "Image ball")
                        gameScene.setAllTypesImageBall();
                    else
                        gameScene.setAllTypesBall3D();
            // new ball drop down box
            JPanel newBallPanel = new JPanel(); // new ball panel
            newBallPanel.setBorder(BorderFactory.createLineBorder(Color.black));
            String[] newType = {"Primary ball", "Pastel ball", "3D ball", "Image ball"}; // Selections for new ball
            newBall = new JComboBox(newType); // Add selections to combo box
            newBallPanel.add(new JLabel("New ball")); // Add combo boxes to new ball panel
            newBallPanel.add(newBall);
            // Add combo box actions
            newBall.addActionListener(new ActionListener() // Add selection listener to newBall combo box
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    String ballType = (String) newBall.getSelectedItem();
                    if (ballType == "Primary ball")
                        gameScene.addBall(new PrimaryBall(gameScene));
                    else if (ballType == "Pastel ball")
                        gameScene.addBall(new PastelBall(gameScene));
                    else if (ballType == "Image ball")
                        gameScene.addBall(new ImageBall(gameScene));
                    else
                        gameScene.addBall(new Ball3D(gameScene));
                    updateSelectBallComboBox();
                    changeSelectedBall(gameScene.getBalls().size() - 1); // Update interface to show new ball
            // selected ball panel
            JPanel selectedBallPanel = new JPanel(); // selected ball panel
            selectedBallPanel.setBorder(BorderFactory.createLineBorder(Color.black));
            // Select ball
            selectBall = new JComboBox(gameScene.getBallList()); // Add ball list to the select drop down box
            deleteBall = new JButton("DeleteBall"); // Delete button
            // Ball colour
            redBall = new JRadioButton("Red"); // Red choice
            redBall.setSelected(true); // Start as selected
            greenBall = new JRadioButton("Green"); // Green choice
            blueBall = new JRadioButton("Blue"); // Blue choice
            ButtonGroup ballColour = new ButtonGroup(); // So only one colour can be selected at a tim
            ballColour.add(redBall);
            ballColour.add(greenBall);
            ballColour.add(blueBall);
            // Path
            archBall = new JRadioButton("Arch"); // Arch path choice
            archBall.setSelected(true); // Start as selected
            figureOfEightBall = new JRadioButton("Figure of eight"); // Figure of eight path choice
            ButtonGroup ballPath = new ButtonGroup(); // So only one path can be selected at a tim
            ballPath.add(archBall);
            ballPath.add(figureOfEightBall);       
            // Can split
            canSplit = new JCheckBox("Can split", false); // Initialy not selected
            selectedBallPanel.add(new JLabel("Select ball")); // Add components to selected ball panel
            selectedBallPanel.add(selectBall);
            selectedBallPanel.add(deleteBall);
            selectedBallPanel.add(new JLabel("Ball colour"));
            selectedBallPanel.add(redBall);
            selectedBallPanel.add(greenBall);
            selectedBallPanel.add(blueBall);
            selectedBallPanel.add(new JLabel("Path"));
            selectedBallPanel.add(archBall);
            selectedBallPanel.add(figureOfEightBall);
            selectedBallPanel.add(canSplit);
            // Add select ball drop down box action
            selectBall.addActionListener(new ActionListener() // Add selection listener to selectBall combo box
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    changeSelectedBall(selectBall.getSelectedIndex()); // Change the selected ball using the index from the select ball drop down box
            // Add delete button action
            deleteBall.addActionListener(new ActionListener() // Add selection listener to deleteBall button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    int tempIndex = selectBall.getSelectedIndex(); // Temp index
                    if (gameScene.getBalls().size() > 1) // If there is more than 1 ball left
                        gameScene.removeBall(tempIndex); // Remove ball
                        updateSelectBallComboBox(); // Update with new ball list
                        changeSelectedBall(tempIndex - 1); // Update interface with new current selected ball
            // Add radio button colour actions
            redBall.addActionListener(new ActionListener() // Add button listener to redBall button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    if (currentBall.getColour() != 0)
                        currentBall.setColour(0); // currentBall colour = red
            greenBall.addActionListener(new ActionListener() // Add button listener to greenBall button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                    if (currentBall.getColour() != 1)
                        currentBall.setColour(1); // currentBall colour = green
            blueBall.addActionListener(new ActionListener() // Add button listener to blueBall button
                public void actionPerformed(ActionEvent ev) // Background colour = blue
                    if (currentBall.getColour() != 2)
                        currentBall.setColour(2); // currentBall colour = blue
            // Add path radio button actions
            archBall.addActionListener(new ActionListener() // Add button listener to arch button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                        currentBall.setPath(new Arch()); // Arch
            figureOfEightBall.addActionListener(new ActionListener() // Add button listener to figureOfEight button
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                        currentBall.setPath(new FigureOfEight()); // Figure of eight
            // Add can split check button actions
            canSplit.addActionListener(new ActionListener() // Add button listener to can split
                public void actionPerformed(ActionEvent ev) // Overide actionPerformed() method
                        currentBall.setCanGiveBirth(canSplit.isSelected()); // Ball can split if can split check button is selected
            // Add components to ball panel
            ballsPanel.add(setAll);
            ballsPanel.add(newBallPanel);
            ballsPanel.add(selectedBallPanel);
            return ballsPanel;
         * changeSelectedBall
         * @param  ballIndexIn - The numbered index of the ball in the game scene list of balls. If less than 0 then equals 0. If more than ball list size then equals last ball
        public void changeSelectedBall(int ballIndexIn)
            if (ballIndexIn < 0) // Make sure index is within bounds
                ballIndexIn = 0;
            else if (ballIndexIn >= gameScene.getBalls().size())
                ballIndexIn = gameScene.getBalls().size() - 1; // Else put within bounds at either end
            currentBall.highlight(false); // Unhighlight current ball
            currentBall = gameScene.getBall(ballIndexIn); // Get new current ball
            currentBall.highlight(true); // Highlight new current ball
            // Update controls to new ball
            selectBall.setSelectedIndex(ballIndexIn);
            switch (currentBall.getColour()) // Update colour controls
                case 0: redBall.setSelected(true); break;
                case 1: greenBall.setSelected(true); break;
                default: blueBall.setSelected(true); break;
            if (currentBall.getPath() instanceof Arch) // If path is arch
                archBall.setSelected(true); // Update controls as arch
            else
                figureOfEightBall.setSelected(true); // Else figure of eight
            canSplit.setSelected(currentBall.canGiveBirth()); // Set if the ball can split or not
         * updateSelectBallComboBox
         * This method updates the combo box selection model with a new one made from the updated balls arraylist from the game scene
        public void updateSelectBallComboBox()
            DefaultComboBoxModel model = new DefaultComboBoxModel(gameScene.getBallList());
            selectBall.setModel(model);
    }Kind regards
    Liam morren

    http://docs.info.apple.com/article.html?artnum=301073
    This link states Mac OS X 10.4 now supports Java 5.0. It does mention nothing about Mac OS 9 or previous version of OS X. The problem you may be facing is that your Mac is running only 1.4.2 or less. The class files compiled for Java 5.0 can't run in non 5.0 versions of the Java Virtual Machine. Java 5.0 was a major release for the Java language and thus the change in numbering (though it took a little bit for this to change).
    Anyway you should confirm what version of Java you have installed on your Mac.
    At a command prompt:
    java -version
    The above URL states that the previous 1.4.2 Java version is not uninstalled, and this could still be the preferred version to use for Java applications even after installing Java 5.0.
    The URL above states there is a utility to set your apps to use Java 5.0 as the perferred Java version. Who knows maybe this is all you need to do. I hope this is the case, then it probably is an easy fix, otherwise you may need to rewrite your app in Java 1.4.2 to get it to run on your version of Mac.

  • Swing Layouts

    Why is laying out component sizes in Swing so incredibly opaque?
    Each time I build a swing interface it seems to be a series of visual compromises, and ending up in more TLOC than any other part of even a complex application. Changing one value seems to always mess up everything else or have unexpected side-effects! Half the time, changing the most obvious values have no effect at all. I frequently end up just clearing out ALL layout hints/settings from the UI and starting from scratch with a GridBagLayout just to get something fairly sensible. Yes I am frustrated.
    If any part of the increasingly wonderful java platform needs a major review, then it is the Swing layout APIs or at least the documentation of the exact behaviour and dependencies of methods that influence sizes.
    Either I am stupid (which I would be most willing to accept), or component layout/orientation/sizing/behaviour is very, very far from intuitive.
    I'd love to become a Swing-super-guru-expert, but as I am expected to be an expert on so many other things, I simply do not have the time to spend on it. I believe that it would be much better for the platform as a whole if the UI platform was made more intuitive or at the very least much better documented.
    I am seriously considering moving to SWT, as I just don't have the time or energy to figure all this out.
    /k1

    Oh btw - all the GUI editors I've ever used tend to compound the problems by introducing their own
    quirks, dependencies and restrictions! That's been my experience to date which is why I've steered clear of them.
    As far as swing architecture not being mature. I think the architecture gives you the building blocks, from there any layout mangers can be created. Maybe Sun could provide a few more LayoutManagers but I suspect their tactic is to provide the minimum from which you can do everything so keeping the API size down.
    So don't restrict yourself to those available in the JDK. Have a google and get some freebies. There are all sorts of alternative Layouts there. The fact that these are freely available elsewhere is quite likely why SUn haven't bothered to introduce more themselves some that spring to mind are TableLayout, GridLayout, ProportionalLayout, LabelledLayout
    To my mind it's the beauty of swing that allows it to be so easily extended in this way.
    SpringLayout came in in JDK1.4 http://www.onjava.com/pub/a/onjava/2002/09/11/layout.html but I'm not familiar with that as yet as I write systems that must be JDK1.3 compatible. It looks like a better replacement for GridBagLayout there are probably alternative versions of this to be found on the web..

  • Problem relating painting swing component

    Hi All,
    I am making a swing application in which there is one central Panel on which i am showing some dynamic contents from database
    but the problem is that data is comming from database but it is not painted automatically on screen and when i move mouse to central panel the contents are printed.
    plz help me
    how i do this painting imidiately .
    Thanx

    Hi All,
    i am using repaint() after each update but the panel is not painted automatically the panel appears when i thake mouse over that panel.
    in my screen there is on treePanel which contains tree now
    i want my centerpanel of screen to be dynamic that is of click on any
    node of the tree it display its summry this summry is comming fron database.
    for this on each mouse click of tree node i first clear the centralPanel
    then add another panel in this centralPanel.
    but the only problem is that it is not reflected imidiately.
    if i move mouse to centralPanel the updates are reflected very quickly.
    help me Plz
    Thanx

  • Memory leak with 1.6.0_07 in applet using Swing

    Java Plug-in 1.6.0_07
    Using JRE version 1.6.0_07 Java HotSpot(TM) Client VM
    Windows XP - SP2
    I have a commercial application that has developed a memory leak with the introduction of the latest plugin. The applets chew up memory and eventually freeze. They did not before. Using jvisualm I see a build up of native arrays, primarily int[][] and char[]. I'm still investigating. Anyone have a similar experience?
    The Applet uses a swing interface, uses buffered images and swing timers, and regularly performs http connections to the server which result in actions via the SwingUtil.invokeLater() method.

    I am Using Internet Explorer Browser Version 6.0.Huge security hole.
    Its not throwing Error / Exception Wrap a try/catch at the highest level possible.
    Catch 'Throwable'. And log/display it somewhere.

  • Question on Swing, MVC and Events (Best Practices)

    Hi,
    I'm making a Swing application trying to follow the MVC pattern. To that end, I have an ApplicationView class and an ApplicationController class (as well as a DataModel). Obviously, I want to have the view as loosely coupled to the controller as possible so I can swap out the GUI later on if I want to. To that end, my controller is creating an instance of this view and passing it via its constructor a sub-class of ActionListener I created. This sub-class is an inner class of the model and basically handles all the button clicks and menu selections from the view and responds accordingly. My question is, is this the best approach or can someone reccomend a better way? Thanks in advance.

    Basically I have the same question, and I have frenetically been looking for a good answer to this... I've found that a common practice is to use actionlisteners (actually, all kinds of listeners) as nested classes in the GUI-code, also use a separate actionlistener for each event, e.g. having one actionlistener to handle events fired from one specific button, another actionlistener for another button etc.
    But this inevitally means that you get the GUI-code (more or less) interwoven with the source-code of your application. The positive effects of this is of course easy access to variables and graphical components in the rest of the code. But the downside is a potentially hard code to read and debug, also you make it difficult to separate the GUI-code from the source-code, if you for instance wanted to use the same GUI in another application.
    Take a look at the following code example (ListDemo.java) that uses several nested listener classes:
    http://java.sun.com/docs/books/tutorial/uiswing/components/list.html
    to download the app:
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/ListDemo.java
    Well this isn't perhaps much of an answer, it may however shed some light on matter.
    I would very much like to elaborate on this subject, so if anyone knows or has any practical examples of how to best use listeners and Swing-applications please feel free to reply this message or e-mail me personally at [email protected]
    All contributions are truly welcommed!
    Thanks
    /Mikael

  • JAX-RPC and Parameter Interfaces

    I am designing the Web Service interface for our project using JAX-RPC, and have enjoyed the ease with which I can create Web Service deployments and WSDL documents.
    However, some of the developers on my team have chosen to create their Data Transfer Objects as a pair of Interface and Implementation classes. This works okay in scenario where the WS caller is "pulling" data from my service. However, it doesn't work in the scenario where the caller is "pushing" data to the service because JAX-RPC can't make the connection between the interface and implementation classes used in my service interface.
    For example, suppose there are four classes in the project: MyService, MyServiceImpl, Foo, and FooImpl. The MyService class uses Foo in it's method signatures. How does JAX-RPC know to instantiate an instance of FooImpl for incoming requests?
    public class MyServiceImpl implements MyService {
    // not ok
    public void doStuff (Foo arg) { ... }
    // ok
    public Foo giveMeStuff () { ... }
    It would be nice if JAX-RPC provided annotations that facilitated making connections between interfaces and implementation classes used in service inputs and outputs. For example:
    @WebServiceInterface {
    Implementation=FooImpl
    public Foo {
    Any thoughts? Thanks,
    Scott Kidder
    http://urlgrey.net/

    Found some answer from the following link
    http://forum.java.sun.com/thread.jsp?forum=331&thread=465860

Maybe you are looking for