AppletContext within ActionListener..Help!!

Hello,
How can I use AppletContext in actionlistener that is being called by an applet in another class. All I need is on click on that applet, I wanted to open a document or an HTML page. I am using this code, Please see below and help me.
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import java.applet.*;
import java.net.*;
public class Chat1 extends Applet
     Color color1 = Color.white;
     public void init()
          setLayout(new FlowLayout());
          Chat2 button1 = new Chat2("Chat"); // this string "Chat" acts as an applet. On click of this string, I wanted to opea a document
          add(button1);
          setBackground(color1);
          ChatActionListener listener = new ChatActionListener();
          button1.addActionListener(listener);
class ChatActionListener implements ActionListener
     public ChatActionListener(){ }
     public void actionPerformed(ActionEvent ae)
          if(ae.getActionCommand().equalsIgnoreCase("Chat"))
     System.out.println("Clicked:" +ae.getActionCommand());
     try{
     //AppletContext ac;
     ac = getAppletContext();
     //URL url1 = new URL("YellowPages1.html");
     //ac.showDocument(url1);
     catch(Exception e){e.printStackTrace();}
Thanks for any help.
Uma

Change
ChatActionListener listener = new ChatActionListener();
to
ChatActionListener listener = new ChatActionListener(getAppletContext());
And rewrite the listener like this:
class ChatActionListener implements ActionListener
private AppletContext ac;
public ChatActionListener(AppletContext ac) {
    this.ac = ac;
public void actionPerformed(ActionEvent ae)
if(ae.getActionCommand().equalsIgnoreCase("Chat"))
System.out.println("Clicked:" +ae.getActionCommand());
try{
URL url1 = new URL("YellowPages1.html");
ac.showDocument(url1);
catch(Exception e){e.printStackTrace();}
}

Similar Messages

  • Swing ActionListener help?

    Hi there,
    I'm trying to get to grips with Swing and I'm reasonably comfortable with laying out the GUI now. However, I'm still trying to get to grips with ActionListeners. As I understand it, you can have any old class as an ActionListener as long as it implements the ActionListener interface.....then you can just add this ActionListener to a component using .addActionListener().
    Couple of questions though....
    1. Is it generally bad design to just have a component call <whatever>.addActionListener(this) and then just implement the actionPerformed() method within the same class?
    2. Do you have to define a seperate ActionListener class for each type of component, or can you use one ActionListener for, say, one whole GUI screen? How do you usually organise these things?
    3. Anyone point me towards some decent tutorials on Java Swing event-handling?....preferably not the Sun ones, although if they are regarded as the best, I'll take 'em. :)
    Thanks for your time.

    URgent help need.
    i need to link the page together : by clicking the button on the index page.
    it will show the revelant class file. I have try my ationPerformed method to the actionlistener, it cannot work.
    Thanks in advance.
    // class mtab
    // the tab menu where it display the gui
    import javax.swing.*;
    import java.awt.*;
    public class mtab {
    private static final int frame_height = 480;
    private static final int frame_width = 680;
    public static void main (String [] args){
    JFrame frame = new JFrame ("Mrt Timing System");
    frame.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE);
    frame.setSize(frame_width,frame_height);
    JTabbedPane tp = new JTabbedPane ();
    tp.addTab("Mrt Timing System", new sample());
    frame.setResizable(false);
    frame.getContentPane().add(tp);
    frame.setSize(680,480);
    frame.show();
    // index page
    // class sample
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Image;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import java.text.*;
    import javax.swing.border.*;
    class sample extends JPanel implements ActionListener
    //button
    private JButton TimingButton;
    private JButton ViewButton;
    private JButton FrequencyButton;
    private JButton calculateButton;
    private CardLayout mycard;
    private JPanel SelectXPanel;
    private JPanel SelectYPanel;
    private JPanel SelectZPanel;
    private JPanel bigFrame, mainPane;
    // constructor
    public sample() {
    super(new BorderLayout());
    //create the object
    //create button and set it
    TimingButton = new JButton("MRT Timing Calculator");
    TimingButton.addActionListener(this);
    ViewButton = new JButton("View First and Last Train");
    ViewButton.addActionListener(this);
    FrequencyButton = new JButton("Show the Train Frequency");
    FrequencyButton.addActionListener(this);
    // Layout
    //Lay out the button in a panel.
    JPanel buttonPane = new JPanel(new GridLayout(3,0));
    buttonPane.add(TimingButton);
    buttonPane.add(ViewButton);
    buttonPane.add(FrequencyButton);
    // Layout the button panel into another panel.
    JPanel buttonPane2 = new JPanel(new GridLayout(0,1));
    buttonPane2.add(buttonPane);
    tfrequency x = new tfrequency();
    fviewl2 y = new fviewl2 ();
    timing z = new timing ();
    JPanel SelectXPanel = new JPanel(new GridLayout(0,1));
    SelectXPanel.add(x);
    JPanel SelectYPanel = new JPanel(new GridLayout(0,1));
    SelectYPanel.add(y);
    JPanel SelectZPanel = new JPanel(new GridLayout(0,1));
    SelectZPanel.add(z);
    // Layout the button by putting in between the rigid area
    JPanel mainPane = new JPanel(new GridLayout(3,0));
    mainPane.add(Box.createRigidArea(new Dimension(0,1)));
    mainPane.add(buttonPane2);
    mainPane.add(Box.createRigidArea(new Dimension(0,1)));
    mainPane.setBorder(new TitledBorder("MRT Timing System"));
    // x = new tfrequency();
    // The overall panel -- divide the frame into two parts: west and east.
    JPanel bigFrame = new JPanel(new GridLayout(0,2));
    bigFrame.add(mainPane, BorderLayout.WEST);
    //bigFrame.add(x,BorderLayout.EAST); // this is where i want to link the page
    // this page being the index page. there being nothing to display.
    add(bigFrame);
    //Create the GUI and show it. For thread safety,
    public void actionPerformed (ActionEvent e){
    if (e.getSource() == TimingButton ){
    JPanel bigFrame = new JPanel(new GridLayout(0,2));
    bigFrame.add(mainPane, BorderLayout.WEST);
    bigFrame.add(SelectZPanel,BorderLayout.EAST);
    add(bigFrame);
    else if (e.getSource() == ViewButton ){
    JPanel bigFrame = new JPanel(new GridLayout(0,2));
    bigFrame.add(mainPane, BorderLayout.WEST);
    bigFrame.add(SelectYPanel,BorderLayout.EAST);
    add(bigFrame);
    else if (e.getSource() == FrequencyButton ){
    JPanel bigFrame2 = new JPanel(new GridLayout(0,2));
    bigFrame.add(mainPane, BorderLayout.WEST);
    bigFrame.add(SelectXPanel,BorderLayout.EAST);
    add(bigFrame);
    // Train Frequency Page
    // class fviewl2
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Image;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import java.text.*;
    import javax.swing.border.*;
    class fviewl2 extends JPanel implements ActionListener
    //Labels to identify the fields
    private JLabel stationLabel;
    private JLabel firstLabel;
    private JLabel lastLabel;
    //Strings for the labels
    private static String station = "MRT Station:";
    private static String first = "First Train Time:";
    private static String last = "Last Train Time:";
    //Fields for data entry
    private JFormattedTextField stationField;
    private JFormattedTextField firstField;
    private JFormattedTextField lastField;
    //button
    private JButton homeButton;
    private JButton cancelButton;
    private JButton calculateButton;
    public fviewl2()
    super(new BorderLayout());
    //create the object
    //Create the Labels
    stationLabel = new JLabel(station);
    firstLabel = new JLabel (first);
    lastLabel = new JLabel (last) ;
    //Create the text fields .// MRT Station:
    stationField = new JFormattedTextField();
    stationField.setColumns(10);
    stationField.setBounds(300,300,5,5);
    //Create the text fields // First Train Time:
    firstField = new JFormattedTextField();
    firstField.setColumns(10);
    firstField.setBounds(300,300,5,5);
    //Create the text fields //Last Train Time:
    lastField = new JFormattedTextField();
    lastField.setColumns(10);
    lastField.setBounds(300,300,5,5);
    //Tell accessibility tools about label/textfield pairs, matching label for the field
    stationLabel.setLabelFor(stationField);
    firstLabel.setLabelFor(firstField);
    lastLabel.setLabelFor(lastField);
    //create button and set it
    homeButton = new JButton("Home");
    //homeButton.addActionListener(this);
    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(this);
    calculateButton = new JButton("Get Time");
    // Layout
    //MRT Station Label // insert into the panel
    JPanel StationPane = new JPanel(new GridLayout(0,1));
    StationPane.add(stationLabel);
    //MRT Station input field // insert into the panel
    JPanel StationInput = new JPanel(new GridLayout(0,1));
    StationInput.add(stationField);
    //Get Time Button // insert into the panel
    JPanel GetTime = new JPanel(new GridLayout(0,1));
    GetTime.add(calculateButton);
    //Lay out the labels in a panel.
    JPanel FlabelL = new JPanel(new GridLayout(0,1));
    FlabelL.add(firstLabel);
    FlabelL.add(lastLabel);
    // Layout the fields in a panel
    JPanel FFieldL = new JPanel(new GridLayout(0,1));
    FFieldL.add(firstField);
    FFieldL.add(lastField);
    //Lay out the button in a panel.
    JPanel buttonPane = new JPanel(new GridLayout(1,0));
    buttonPane.add(homeButton);
    buttonPane.add(cancelButton);
    // Layout all components in the main panel
    JPanel mainPane = new JPanel(new GridLayout(4,2));
    mainPane.add(StationPane);
    mainPane.add(StationInput);
    mainPane.add(Box.createRigidArea(new Dimension(0,1)));
    mainPane.add(GetTime);
    mainPane.add(FlabelL);
    mainPane.add(FFieldL);
    mainPane.add(Box.createRigidArea(new Dimension(0,1)));
    mainPane.add(buttonPane);
    mainPane.setBorder(new TitledBorder("View First and Last Train"));
    JPanel leftPane = new JPanel(new GridLayout(1,0));
    leftPane.add(Box.createRigidArea(new Dimension(0,1)));
    leftPane.add(mainPane);
    leftPane.add(Box.createRigidArea(new Dimension(0,1)));
    JPanel hahaFrame = new JPanel(new GridLayout(0,1));
    hahaFrame.add(Box.createRigidArea(new Dimension(0,1)));
    hahaFrame.setBorder(BorderFactory.createEmptyBorder(30, 10, 80, 150));
    hahaFrame.add(Box.createRigidArea(new Dimension(0,1)));
    JPanel bigFrame = new JPanel();
    bigFrame.add(hahaFrame, BorderLayout.NORTH);
    bigFrame.add(leftPane, BorderLayout.CENTER);
    add(bigFrame, BorderLayout.CENTER);
    //Create the GUI and show it. For thread safety,
    private void cancelButtonClicked()
    stationField.setText("");
    firstField.setText("");
    lastField.setText("");
    public void actionPerformed (ActionEvent e){
    if (e.getSource() == cancelButton){
    cancelButtonClicked();
    }

  • Graphics within F1 help

    Hi all,
    has anyone an idea how to insert a graphic into my F1-help.
    It seems that F1 processor has some problems with it because  if I print my dokument the graphic is shown correctly only within performance assistant (or modal f1 window) the graphic is not shown.
    Any help is highly welcomed!
    Thanks!
    Best regards
    Tobias Kugelmann

    You have something called the AWT Event Thread. This is what does all windowing events. If you press a button, the ActionListener is ran in this thread. If you paint the screen, it too is done in this thread.
    Now you are adding delays in the paint method (from the sounds of it), so you send the current thread (which is the AWT event thread) to sleep. Now you application can no longer do anything GUI (hear mouse clicks, repaint other components) while this thread is asleep.
    This is why you are having the problems you are having.
    To fix it you need a datamodel. The circles represent something I would guess, so don't paint circles. Paint Thingies (which are represented by circles).
    The paint method has to be changed so instead of handing the loop, it looks at the data model to see how many Thingies it has to draw, and where.
    You the use a different loop (either main(), or a TimerTask) to add the Thingies into the datamodel, and call repaint.

  • Trying to create object of a class within servlet - help!!

    I have created and compiled the following classes within
    C:\bea\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\classes
    1)LoginServlet
    2)LoginManager
    3)I have LoginServlet trying to create an object of type LoginManager, very simple,
    but I get the following errors:
    Cannot resolve symbol: LoginManager lm = new LoginManager();
    ^
    Cannot resolve symbol: LoginManager lm = new LoginManager();
    ^
    4)I have the .java and .class files located within the same directory, so I don't
    see what's wrong here??? HELP!
    LoginManager looks like:
    public class LoginManager {
    public boolean authenticateUser(String username, String password){
              boolean status = false;
    //simple code for string matching
              return status;
    LoginServlet looks like:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class LoginServlet extends HttpServlet {
         // Constructors
         // Variables
         public static final String CONTENT_TYPE = "text/html";
         public boolean LOGIN_STATUS;
         // Methods
         public void service (HttpServletRequest req, HttpServletResponse res)
              throws IOException {
              String username = "";
              String password = "";
              LoginManager lm = new LoginManager();
              username = req.getParameter("username");
              password = req.getParameter("password");
              LOGIN_STATUS = lm.authenticateUser(username, password);
              res.setContentType(CONTENT_TYPE);
              PrintWriter out = res.getWriter();
              out.println("<html><head><title>Hello World</title></head>" +
                             "<body>Hello! Your login status is " + LOGIN_STATUS +
                             "</body>" +
                             "</html>");
         public void init (ServletConfig config) throws ServletException {
              super.init(config);

    Do you have . in the CLASSPATH when compiling your servlet?
    ron <[email protected]> wrote:
    I have created and compiled the following classes within
    C:\bea\wlserver6.1\config\mydomain\applications\DefaultWebApp\WEB-INF\classes
    1)LoginServlet
    2)LoginManager
    3)I have LoginServlet trying to create an object of type LoginManager, very simple,
    but I get the following errors:
    Cannot resolve symbol: LoginManager lm = new LoginManager();
    ^
    Cannot resolve symbol: LoginManager lm = new LoginManager();
    ^
    4)I have the .java and .class files located within the same directory, so I don't
    see what's wrong here??? HELP!
    LoginManager looks like:
    public class LoginManager {
    public boolean authenticateUser(String username, String password){
              boolean status = false;
    //simple code for string matching
              return status;
    LoginServlet looks like:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class LoginServlet extends HttpServlet {
         // Constructors
         // Variables
         public static final String CONTENT_TYPE = "text/html";
         public boolean LOGIN_STATUS;
         // Methods
         public void service (HttpServletRequest req, HttpServletResponse res)
              throws IOException {
              String username = "";
              String password = "";
              LoginManager lm = new LoginManager();
              username = req.getParameter("username");
              password = req.getParameter("password");
              LOGIN_STATUS = lm.authenticateUser(username, password);
              res.setContentType(CONTENT_TYPE);
              PrintWriter out = res.getWriter();
              out.println("<html><head><title>Hello World</title></head>" +
                             "<body>Hello! Your login status is " + LOGIN_STATUS +
                             "</body>" +
                             "</html>");
         public void init (ServletConfig config) throws ServletException {
              super.init(config);
    Dimitri

  • ActionListener Help

    Hi
    I am creating a very basic program that has two buttons and a text field. When any button is clicked, then the text in the text field should change. However, I've run into a problem with the actionPerformed method - it doesn't seem to recognise the names of my buttons i.e. *'+button_name +cannot be resolved'*. So, when I click the button then nothing happens. The code is not very large so I'll provide it below.
    import javax.swing.*;*
    import java.awt.event.;
    import java.awt.*;
    public class SGUI extends JPanel implements ActionListener{
    public SGUI() {
    ImageIcon hello = createImageIcon("images/hello.gif");
    ImageIcon bye = createImageIcon("images/bye.gif");
    JButton sayHello = new JButton(hello);
    JButton sayBye = new JButton(bye);
    JTextField message = new JTextField("What shall I say?");
    message.setBackground(Color.blue);
    message.setForeground(Color.WHITE);
    //Listen for actions on the 2 buttons and text field.
    sayHello.addActionListener(this);
    sayBye.addActionListener(this);
    message.addActionListener(this);
    sayHello.setToolTipText("display greeting");
    sayBye.setToolTipText("display farewell");
    //add components to container using flowLayout
    add(sayHello);
    add(sayBye);
    add(message);
    public void actionPerformed(ActionEvent ae){
    if (ae.getSource()==sayHello){
    message.setText("Hello!");
    } //respond to the button pressed
    protected static ImageIcon createImageIcon(String path) {
    java.net.URL imgURL = SGUI.class.getResource(path);
    if (imgURL != null) {
    return new ImageIcon(imgURL);
    } else {
    System.err.println("Couldn't find file: " + path);
    return null;
    private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("HelloGoodbye");
    //Create and set up the content pane.
    SGUI newContentPane = new SGUI();
    newContentPane.setOpaque(true); //content panes must be opaque
    newContentPane.setBackground(Color.yellow);
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setSize(300, 300);
    frame.setVisible(true);
    //run the program
    public static void main(String[] args) {
    createAndShowGUI();
    }The _{color:#ff0000}red lines{color}_ appear underneath sayBye+ and message in the actionPerformed() method, which results in the actionPerformed method not working - although the actual program still runs*. Please help!
    Edited by: aras298 on May 5, 2008 8:49 AM

    you appear to have a problem of scope: your JButtons are declared and defined in the constructor and have a scope that is confined to the constructor. Anything that's outside of the constructor will thus not be able to "see" these components. One solution: make the buttons declared in the class. You can still construct them in the constructor, but make sure that their scope is the entire class, not just the constructor.
    Also, I recommend that you start getting in the habit of not having your main GUI classes implement the ActionListener interface, but rather using anonymous inner classes, or private inner classes, or stand-alone classes for your actionlisteners. It's much cleaner this way.

  • Button / actionlistener help

    Hi,
    I'm slowly writing a applet, that when you press a button(a.k.a btnOn), it gets replaced with another button (a.k.a btnOff) and vice versa. I would appreciate any help that anyone would give. This is part of a game that i am trying to make, with very little success. So any help would be appreciated. Thanks.
    p.s. i know this is probably a really easy question, but for some reason i just can't figure it out.
    thanks

    Well i tried to change michael's code, i don't know if i did it right though... i probably didn't
    but here you go:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.*;
    * Class l0gixGame - write a description of the class here
    * @author (your name)
    * @version (a version number)
    public class logixGame extends JApplet implements ActionListener {
        JButton btnOn,btnOff;
        private static final ImageIcon image[]={
            new ImageIcon("On.png"),
            new ImageIcon("Off.png")};
       public void init(){
           /** creates the control panel, sets the size,locaiton and the background
            * colour
           JPanel controlPanel = new JPanel();
           controlPanel.setSize(new Dimension(400,275));
           controlPanel.setLocation(10,100);
           controlPanel.setBackground(Color.gray);
           /** creates the background panel, sets the size,locaiton and the
           * background color
           JPanel backGround = new JPanel();
           backGround.setSize(new Dimension(400,400));
           backGround.setLocation(0,0);
           backGround.setBackground(Color.gray);
           /** creates the play panel, sets the size,locaiton and the
           * background color
           JPanel playPanel = new JPanel();
           playPanel.setSize(new Dimension(400,275));
           playPanel.setLocation(500,200);
           playPanel.setBackground(Color.orange);
           /** creates the layout for the play panel, and the control panel
            * creates the content pane, and the three panels to the content pane
            * and sets the dimensions for the content pane
           controlPanel.setLayout(new GridLayout(8,12));
           playPanel.setLayout(new GridLayout(8,12));
           Container cp = getContentPane();
           cp.setSize(new Dimension(5000,5000));
           cp.add(controlPanel);
           cp.add(playPanel);
           cp.add(backGround);
           /**initialize the onbutton and the offbutton with the related graphics*/
           ImageIcon on = new ImageIcon(getImage(getCodeBase(),
           "On.png"));
           ImageIcon off = new ImageIcon(getImage(getCodeBase(),
           "Off.png"));
           ArrayList<String> control = new ArrayList<String>();
           ArrayList<String> play = new ArrayList<String>();
           /** Randimization of control panel and play panel*/
           /**1=off 2=on*/
           int row,column,i,x,y;
             for( column = 0; column <= 8; column = column+1)
                    for (row = 0; row <= 14; row = row+1)
                        i = 1;
                        y = row * 50;
                        x = column * 50;
                        if ( (column % 2) == (row % 2) )
                            Random r = new Random();
                            int n = r.nextInt();
                            if(n % 2 == 0){
                                 JLabel btn2 = new JLabel(off);
                                controlPanel.add(btn2);
                                control.add("1");
                                JButton btnOn = new JButton(on);
                                btnOn.setBackground(Color.orange);
                                playPanel.add(btnOn);
                                play.add("2");
                            else{
                                JLabel btn2 = new JLabel(on);
                                controlPanel.add(btn2);
                                control.add("2");
                                JButton btnOff = new JButton(off);
                                btnOff.setBackground(Color.orange);
                                playPanel.add(btnOff);
                                play.add("1");
                        else
                            Random r = new Random();
                            int n = r.nextInt();
                            if(n % 3 == 0){
                                JLabel btn2 = new JLabel(on);
                                controlPanel.add(btn2);
                                control.add("2");
                                JButton btnOn = new JButton(on);
                                btnOn.setBackground(Color.orange);
                                playPanel.add(btnOn);
                                play.add("2");
                String controlString =""+ control;
                String playString =""+ play;
                if(controlString.compareTo(playString)==0){
                    JLabel winner = new JLabel("Winner!");
                    backGround.add(winner);
    public void actionPerformed (ActionEvent event) {
       if(btn.getIcon().equals(on))
           btn.setIcon(off);
        else
            btn.setIcon(on);
    }what is the difference between your way of getting the image and mine???
    3) for the moment, i don't really care, i just want to get the individual buttons working, and test out my strategy for winning, even though i am on a time restraint, i think it would be better to hand it in with individual buttons working, then none of the buttons working...
    right know i get a "cannot find symbol -- variable on" in my actionlistener is there a specific reason???
    thanks for the help i do really really appreciate it..... you don't know how much..
    p.s. i told you i wasn't very good at this

  • Buttons and actionlistener help.

    the following code has 2 buttons, how would i use a button to get me differnt graphics but inside the same window,
    say i clicked next the graphics would be slightly altered which I will do but it wont open a new window it will be in the same window, but different shapes.
    I am having trouble with action listeners and really need help in how they work iv read up but dont understand, and how this would be implemented for this.
    much help would be appreciated.
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.RenderingHints;
    import java.awt.Stroke;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Rectangle2D;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class square extends JPanel
        public square()
            setPreferredSize(new Dimension(800, 700));
            int eb = 80;
            setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
            setLayout(new BorderLayout(5, 10));
           JPanel buttonPanel = createButtonPanel();
             add(buttonPanel, BorderLayout.SOUTH);
        private JPanel createButtonPanel()
            JPanel bp = new JPanel();
            bp.setOpaque(false);
                   JButton btn2 = new JButton("<-  Back Step ");
                    JButton btn = new JButton("Next Step   ->");
                    bp.add(btn2);
                    bp.add(btn);
            return bp;
        @Override
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            Rectangle2D rect = new Rectangle2D.Double(250, 150, 100, 100);
            Rectangle2D     rect2 = new Rectangle2D.Double(400, 150, 100, 100);
             Rectangle2D     rect3 = new Rectangle2D.Double(550, 150, 100, 100);
             Rectangle2D     rect4 = new Rectangle2D.Double(250, 300, 100, 100);
             Rectangle2D     rect5 = new Rectangle2D.Double(400, 300, 100, 100);
             Rectangle2D     rect6 = new Rectangle2D.Double(550, 300, 100, 100);
             Rectangle2D     rect7 = new Rectangle2D.Double(250, 450, 100, 100);
             Rectangle2D     rect8 = new Rectangle2D.Double(400, 450, 100, 100);
             Rectangle2D     rect9 = new Rectangle2D.Double(550, 450, 100, 100);
             g.drawString("b0,0", 300, 130);
            g.drawString("b1,0", 300, 110);
             g.drawString("b2,0", 300, 90);
                 g.drawString("b0,1", 450, 110);
            g.drawString("b1,1", 450, 90);
            g.drawString("b2,1", 450, 70);
                 g.drawString("b0,2", 600, 90);
            g.drawString("b1,2", 600, 70);
            g.drawString("b2,2", 600, 50);
             g.drawString("a0,0", 200, 200);
            g.drawString("a1,0", 150, 200);
             g.drawString("a2,0", 100, 200);
                 g.drawString("a0,1", 150, 350);
            g.drawString("a1,1", 100, 350);
            g.drawString("a2,1", 50, 350);
                   g.drawString("a0,2", 100, 500);
            g.drawString("a1,2", 50, 500);
            g.drawString("a2,2", 15, 500);
            g2.setPaint(Color.black);
            g2.draw(rect);
            g2.draw(rect);
              g2.draw(rect2);
             g2.draw(rect3);
              g2.draw(rect4);
             g2.draw(rect5);
              g2.draw(rect6);
             g2.draw(rect7);
              g2.draw(rect8);
              g2.draw(rect9);
            Stroke oldStroke = g2.getStroke();
            g2.setStroke(new BasicStroke(5));
            g2.setStroke(oldStroke);
        private static void createAndShowUI()
            JFrame frame = new JFrame("Matrix Multiplication - Step by Step ");
            frame.getContentPane().add(new square());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }

    ok I had a look over it, I got this
    import java.awt.BasicStroke;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.RenderingHints;
    import java.awt.Stroke;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Rectangle2D;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class square extends JPanel implements ActionListener
        public square()
            setPreferredSize(new Dimension(800, 700));
            int eb = 80;
            setBorder(BorderFactory.createEmptyBorder(eb, eb, eb, eb));
            setLayout(new BorderLayout(5, 10));
           JPanel buttonPanel = createButtonPanel();
             add(buttonPanel, BorderLayout.SOUTH);
      public void actionPerformed(ActionEvent e) {
            System.out.println("hello");
        private JPanel createButtonPanel()
            JPanel bp = new JPanel();
            bp.setOpaque(false);
                   JButton btn2 = new JButton("<-  Back Step ");
                    JButton btn = new JButton("Next Step   ->");
                    bp.add(btn2);
                    bp.add(btn);
             btn.addActionListener(this);
            return bp;
        @Override
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
            Rectangle2D rect = new Rectangle2D.Double(250, 150, 100, 100);
            Rectangle2D     rect2 = new Rectangle2D.Double(400, 150, 100, 100);
             Rectangle2D     rect3 = new Rectangle2D.Double(550, 150, 100, 100);
             Rectangle2D     rect4 = new Rectangle2D.Double(250, 300, 100, 100);
             Rectangle2D     rect5 = new Rectangle2D.Double(400, 300, 100, 100);
             Rectangle2D     rect6 = new Rectangle2D.Double(550, 300, 100, 100);
             Rectangle2D     rect7 = new Rectangle2D.Double(250, 450, 100, 100);
             Rectangle2D     rect8 = new Rectangle2D.Double(400, 450, 100, 100);
             Rectangle2D     rect9 = new Rectangle2D.Double(550, 450, 100, 100);
             g.drawString("b0,0", 300, 130);
            g.drawString("b1,0", 300, 110);
             g.drawString("b2,0", 300, 90);
                 g.drawString("b0,1", 450, 110);
            g.drawString("b1,1", 450, 90);
            g.drawString("b2,1", 450, 70);
                 g.drawString("b0,2", 600, 90);
            g.drawString("b1,2", 600, 70);
            g.drawString("b2,2", 600, 50);
             g.drawString("a0,0", 200, 200);
            g.drawString("a1,0", 150, 200);
             g.drawString("a2,0", 100, 200);
                 g.drawString("a0,1", 150, 350);
            g.drawString("a1,1", 100, 350);
            g.drawString("a2,1", 50, 350);
                   g.drawString("a0,2", 100, 500);
            g.drawString("a1,2", 50, 500);
            g.drawString("a2,2", 15, 500);
            g2.setPaint(Color.black);
            g2.draw(rect);
            g2.draw(rect);
              g2.draw(rect2);
             g2.draw(rect3);
              g2.draw(rect4);
             g2.draw(rect5);
              g2.draw(rect6);
             g2.draw(rect7);
              g2.draw(rect8);
              g2.draw(rect9);
            Stroke oldStroke = g2.getStroke();
            g2.setStroke(new BasicStroke(5));
            g2.setStroke(oldStroke);
        private static void createAndShowUI()
            JFrame frame = new JFrame("Matrix Multiplication - Step by Step ");
            frame.getContentPane().add(new square());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }it produces hello once I click the button, but how would I produce the same frame once the button is clicked, not a new frame, the same one iv got with slight adjustments inside it..which i will do.

  • Help Please Needed for Java Calculator - ActionListener HELP

    Hi. I am constructing a simple Java calculator and need help with the actionlistener and how it could work with my program. I am not too sure how to begin constructing the actionlistener. I would like to know the best and most simple solution to get this program work the way it should, like a real calculator. If anyone can help me, that would be much appreciated.
    package calculator;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class CalculatorGUI extends JFrame implements ActionListener{
    JTextField screen;
    JButton button7;
    JButton button8;
    JButton button9;
    JButton button4;
    JButton button5;
    JButton button6;
    JButton button1;
    JButton button2;
    JButton button3;
    JButton button0;
    JButton add;
    JButton minus;
    JButton multiply;
    JButton divide;
    JButton equals;
    JButton clear;
    private JTextField m_displayField;
    private boolean m_startNumber = true;
    private String m_previousOp = "=";
    private CalculatorLogic m_logic = new CalculatorLogic();
    public CalculatorGUI() {
    CalculatorGUILayout customLayout = new CalculatorGUILayout();
    getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
    getContentPane().setLayout(customLayout);
    screen = new JTextField("textfield_1");
    getContentPane().add(screen);
    button7 = new JButton("7");
    getContentPane().add(button7);
    button7.addActionListener(this);
    button8 = new JButton("8");
    getContentPane().add(button8);
    button8.addActionListener(this);
    button9 = new JButton("9");
    getContentPane().add(button9);
    button9.addActionListener(this);
    button4 = new JButton("4");
    getContentPane().add(button4);
    button4.addActionListener(this);
    button5 = new JButton("5");
    getContentPane().add(button5);
    button5.addActionListener(this);
    button6 = new JButton("6");
    getContentPane().add(button6);
    button6.addActionListener(this);
    button1 = new JButton("1");
    getContentPane().add(button1);
    button1.addActionListener(this);
    button2 = new JButton("2");
    getContentPane().add(button2);
    button2.addActionListener(this);
    button3 = new JButton("3");
    getContentPane().add(button3);
    button3.addActionListener(this);
    button0 = new JButton("0");
    getContentPane().add(button0);
    button0.addActionListener(this);
    add = new JButton("+");
    getContentPane().add(add);
    add.addActionListener(this);
    minus = new JButton("-");
    getContentPane().add(minus);
    minus.addActionListener(this);
    multiply = new JButton("*");
    getContentPane().add(multiply);
    multiply.addActionListener(this);
    divide = new JButton("/");
    getContentPane().add(divide);
    divide.addActionListener(this);
    equals = new JButton("=");
    getContentPane().add(equals);
    equals.addActionListener(this);
    clear = new JButton("Clear");
    getContentPane().add(clear);
    clear.addActionListener(this);
    setSize(getPreferredSize());
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    public void actionPerformed(ActionEvent event) {
    public static void main(String args[]) {
    CalculatorGUI window = new CalculatorGUI();
    window.setTitle("Calculator");
    window.pack();
    window.show();
    class CalculatorGUILayout implements LayoutManager {
    public CalculatorGUILayout() {
    public void addLayoutComponent(String name, Component comp) {
    public void removeLayoutComponent(Component comp) {
    public Dimension preferredLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    Insets insets = parent.getInsets();
    dim.width = 421 + insets.left + insets.right;
    dim.height = 494 + insets.top + insets.bottom;
    return dim;
    public Dimension minimumLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    return dim;
    public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    Component c;
    c = parent.getComponent(0);
    if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+8,408,64);}
    c = parent.getComponent(1);
    if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+80,96,56);}
    c = parent.getComponent(2);
    if (c.isVisible()) {c.setBounds(insets.left+120,insets.top+80,96,56);}
    c = parent.getComponent(3);
    if (c.isVisible()) {c.setBounds(insets.left+232,insets.top+80,96,56);}
    c = parent.getComponent(4);
    if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+144,96,56);}
    c = parent.getComponent(5);
    if (c.isVisible()) {c.setBounds(insets.left+120,insets.top+144,96,56);}
    c = parent.getComponent(6);
    if (c.isVisible()) {c.setBounds(insets.left+232,insets.top+144,96,56);}
    c = parent.getComponent(7);
    if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+208,96,56);}
    c = parent.getComponent(8);
    if (c.isVisible()) {c.setBounds(insets.left+120,insets.top+208,96,56);}
    c = parent.getComponent(9);
    if (c.isVisible()) {c.setBounds(insets.left+232,insets.top+208,96,56);}
    c = parent.getComponent(10);
    if (c.isVisible()) {c.setBounds(insets.left+120,insets.top+272,96,56);}
    c = parent.getComponent(11);
    if (c.isVisible()) {c.setBounds(insets.left+344,insets.top+80,72,56);}
    c = parent.getComponent(12);
    if (c.isVisible()) {c.setBounds(insets.left+344,insets.top+144,72,56);}
    c = parent.getComponent(13);
    if (c.isVisible()) {c.setBounds(insets.left+344,insets.top+208,72,56);}
    c = parent.getComponent(14);
    if (c.isVisible()) {c.setBounds(insets.left+344,insets.top+272,72,56);}
    c = parent.getComponent(15);
    if (c.isVisible()) {c.setBounds(insets.left+344,insets.top+336,72,56);}
    c = parent.getComponent(16);
    if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+408,408,72);}
    }

    Yeah, I have a rough idea of what the calculator
    should do, like most people would. Its just that I
    dont know how to implement this in Java. Thats the
    problem. Can anyone provide me with code snippets
    that I can try?No I would rather see you make an effort from what has been discussed here. This is not a Java problem this is a general programming problem.

  • Can't update form within CS5 help/update

    After opening CS5, going to help and clicking update, I get a message from adobe application manager, the server is down or check settings on firewall. This has been going on from day one after installing,  for months.
    I downloaded the lastest adobe application manager, installed, but still not working.
    What am I doing wrong ?

    Have you checked either your windows firewall settings or your virus scan software
    for blocking of internet connections for cs5?
    You can also update the software manually from:
    http://www.adobe.com/downloads/updates/
    MTSTUNER

  • Tabset actionlistener help

    Could someone please tell me how to add an actionlistener to a tabset?
    I've tried this in init():
            Class[] args = new Class[] { ActionEvent.class };
            MethodBinding binding = createBinding("#{MyPage.tabClicked}", args);
            getTabSet1().setActionListener(binding);with a createBinding of
       private MethodBinding createBinding(String expr, Class[] args) {
            ApplicationFactory factory = (ApplicationFactory)
            FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
            Application app = factory.getApplication();
            return app.createMethodBinding(expr, args);
        }and a listener like this:
       public void tabClicked(ActionEvent event) {
            String selectedTabId = getTabSet1().getSelected();
            info(selectedTabId);
         }This builds and runs ok, but the listener never gets called. I don't see the info() message, and a breakpoint set in the listener never gets hit.
    I'm not sure this is the correct way to go about this. There is an actionListener property in the properties for tabsets, but it just brings up a dialog with a prompt:
    Method binding representing a method that receives action from this component.
    and a textarea to start typing in. If this is the preferred method, how do I go about using it?

    OK, I've researched more, and still no success.
    Apparently, the correct way to do this is to enter the binding method into the actionlistener property of the tabset. Here's what I put:
    #{myPage.tabClicked}
    This creates a nice entry in my .jsp file.
    I then still have the same tabClicked method as above.
    When I run it, I get an exception:
    Exception Details: javax.faces.el.MethodNotFoundException
      tabClicked: myApp.myPage.tabClicked(javax.faces.event.ActionEvent)I also notice that the tabset UI doesn't support addActionListener(), but has a method setActionListener(). This makes me wonder.
    Incidentally, I also tried creating a class that implements actionListener, and instantiating such a class in my page, but that worked just as poorly.

  • Search Help Within Search help

    Hi experts!!
    How can i assign a search help to a field of another elementary search help from SE11???
    I tried to create a new data element but did not work...

    Hi
    <b>Attaching a search help to a field</b>
    A search help can influence the behavior of a field when the input help is called. The search help must be assigned to the field in order to do this. You have the following options for this assignment:
    Attach search help to a data element / table or structure field / screen field / check table.
    Conventionally search helps are attached to table fields or data elements. We shall see the same.
    1)Choose the field name, click on search help tab and
    provide the name of the search help.
    A search help is attached to a field of a table or structure in the maintenance transaction for this table/structure, analogously to attaching to a table. You must assign the interface parameters of the search help to any fields of the table/structure. The search field must be assigned to an EXPORT parameter of the search help at this time.
    2)Attach the search help to the table field
    3)The search help ZSTRAVELAG_NAME is therefore directly attached to the field AGENCYNUM of table ZSTRAVELAG.
    <b>Attaching a search help to a data element</b>
    Provide the search help name and the parameter name
    under the further characteristics tab of the data element.
    If the input help of a field is defined by its data element, no further screen fields can be used in the input help.
    Also note that the input F4 help would be available wherever the data element is used.
    <b>Attaching a search help to a screen element</b>
    A search help can be directly assigned to a screen field in two ways.
    The name of the search help must be entered in the Screen Painter in the Attributes for the field in the field Search help.
    The name of the search help can be defined for selection screens in ABAP reports in the PARAMETERS or SELECT-OPTIONS statement directly following the supplement MATCHCODE OBJECT.
    However, input help is only available for this particular screen.
    Reward if usefull

  • Wierd Time Signature Changes Within Song - HELP!!

    Hey all, I am recording a song with a combo of real vocals & instruments, some loops, and some parts played via soft synth. Many of the recorded parts were originally recorded in Ableton Live, but I slaved it to Logic and re-recorded the parts in Logic tracks so I can continue and finish the song in Logic. It's all been done to a click track at 127 bpm. Between bars 17-20, the time signature changes radically, and it shows in the display at the top above the tracks. I don't know how this happened, or how to change it. Everything gets condensed to a smaller signature, although I cannot think of a better way to explain it. I took a screen shot and would be happy to email it to anyone (I don't know how to embed images in these posts). I am in desperate need of help here as this little glitch throws off the click for the remainder of the song. Thanks in advance for your help!!

    Just position the playhead to bar 17 and change the time signature in the transport window to how it should be (e.g. like the rest of the song). Do the same in the following bars if needed. This actually deletes the "wrong" time signatures and sets everything back to "normal".

  • JTextField ActionListener Help

    Hallo Guys,
    I have an JTextField . when the user inputs the number and clicks the InsertString button i generate that many JTextField for the user to insert some Strings.
    if the user enters 10 and clicks the InsertString Button then 10 JTextFields appear. it works fine
    but my problem is how to access the text entered in the different JTextFields.
    i can access only the last textField
    Here is the piece of code
    if(cmd.equals("InsertString"))
         if(numvaluesField.getText().equals(""))
         ImageIcon icon = new ImageIcon("Images/warning_large.gif");
         JOptionPane.showConfirmDialog(null,"Please Input the Number of Values and then Press the InsertString Button","Alert",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,icon);
         else
              stringButton.setEnabled(false);
              deleteButton.setEnabled(true);
              Container contentPane = valueFrame.getContentPane();
              GridBagLayout gridbag = new GridBagLayout();
              sub1 = new JPanel(gridbag);
              GridBagConstraints c = new GridBagConstraints();
              GridBagConstraints d = new GridBagConstraints();
              c.anchor = GridBagConstraints.CENTER;
             c.fill = GridBagConstraints.BOTH;
             c.insets = new Insets(5, 5, 5, 5);
             c.weightx = 1.0;
             c.weighty = 1.0;
             try{
              numValue = Integer.parseInt(numvaluesField.getText());
             catch(NumberFormatException exception){};
         if(numvaluesField.equals(""))
              JOptionPane.showConfirmDialog(null,"The number of values field Cannot be NULL","Alert",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE);
         else{
         for(int i = 1; i <= numValue ; i++)
              c.gridx = 2 ;
              c.gridy = i ;
              lengthField.setText(String.valueOf(Integer.parseInt(lengthField.getText()) + 2));
              JLabel stringLabel= new JLabel("String"+i+":");
              sub1.add(stringLabel,c);
              //stringField = new JTextField[numValue];
              stringField = new JTextField(10);
              stringField.addActionListener(this);
              stringField.setToolTipText("Enter the String name for Parameter Acquisition");
              c.gridx = 3;
              c.gridy = i;
              sub1.add(stringField,c);
              d.gridx = 1;
              d.gridy = 0;
              main.add(sub1,GridBagConstraints.RELATIVE);
              contentPane.add(main);
              valueFrame.setContentPane(contentPane);
              valueFrame.pack();
    }here is the code where i access the JTextFields
    for(int i = 1 ; i <= numValue1 ; i++)
         StringBuffer buff = new StringBuffer();
         buff.append(stringField.getText());     
    value = messageString.createStringField(value,buff.toString());
         buff.setLength(0);
    }

    Hi freedomjava,
    Torajirou is right you'r overwrite the reference so the only textfield available is the last one..
    For simple example you just think what should be the out put of the following ?? and you should got your mistake..
             int i=0;
             i=1;
             i=100;
             System.out.println("Value of i  = "+i);You should got the last value....

  • Multiplication within array help

    Hiall,
    paulcw
    suggested i use this for multiplication
    how do i apply this to my code
    Im not even sure how this works!
    total = quantity * cost[lastElt];
    here is the code i need to work on
    System.out.println("Part No." +"\t"+ "Qty Avail." +"\t"+ "Cost Price." +"\t"+ "Retail Price.");// this just prints these words on the screen
    System.out.println(input_part +"\t"+ "\t" + qty[input_part-1]+"\t"+ "\t" + cost[input_part-1] +"\t"+ "\t" + retail[input_part-1]+"\t"+ "\t" + "\n"); //this prints all quntities price etc
    System.out.println("Total cost." +"\t"+ "Total Retail.");//this also prints the words in ""
    i need to know how to write the code to multiply the:-
    qty x cost of a part number
    and
    qty X retail of apart number
    and print these below the words Toatl cost and Total retail
    any hepl or tips greatly appreciated
    Paul

    "qty x cost of a part number"
    If "qty[input_part-1]" is the qty and "cost[input_part-1]" is the cost then just write a multiply line. What do you want to do with the result? For example, to display the result of the multiplicationSystem.out.println(qty[input_part-1] * cost[input_part-1]);

  • TS3991 my icloud account backs up my contacts and then they disappear within seconds. help

    my icloud backs up my contacts and then seconds later they are deleted.  there was a second device on the icloud that is now separated and that is where the original deletion was performed.  using the backup from before this device  interfered allows the contacts to reappear for only a few seconds.  then they are gone again.  help

    If you are trying to restore contacts from your iCloud backup and they are being overwritten when your device reconnects to iCloud, follow the steps in this user tip from Winston Churchill: https://discussions.apple.com/docs/DOC-4841.

Maybe you are looking for

  • Will Cumulative Update 12 for SQL Server 2008R2 SP2 fix: Warning: Unable to Verify TimeStamp for Path\ProgramName?

    Hello, I had a server crash recently and our outsource hosting tech support suggested applying Cumulative Upade 12 for SQL server 2008R2 SP2 to fix the issue.  The exception from our dump file "Warning: Unable to Verify TimeStamp for Path\ProgramName

  • How can we restrict the searchhelp in sm30

    Hello experts...      i have created search helps for the fields of ztable. in the sm30 display it is showing f4 help and taking values in to that, my problem is even it is taking the values those are not in the searchhelp table....   how can i restr

  • A question about using SQL*Plus

    script: spool c:/abc.bin select * from abc when I press ENTER, the result will be orderly shown on the screen. In fact, I want to input "spool off" to save the result into the file, but I have to wait for the screen finishing its showing. Which comma

  • Can't access iCloud email after update to 10.7.4

    After updating to System 10.7.4, I can't access my iCloud email account on any of my devices (computer and iPhone 4S). The servers are not recognizing my email password, which is the same as my Apple ID password.  I can log in to iCloud using Safari

  • How to add custom columns with BO data from GP to UWL

    Hi We have CE 7.1 in our project UWL taskitems only have GP workflow tasks. In UWL we can see that by default there are standard columns but now we need to add custom columns with data from ours BO associated to process instance For that we need to d