MouseListener is not Working ....

Problem is like this......
I have made a class TakeInput......this class uses an object of another class ViewPanel
to display an Image. ViewPanel is an Inner class of TakeInput. Mouse handling has been
used in the class ViewPanel to point out the pixels of the image. ViewPanel uses an Instance of
another Class ImageView to display image in which no mousehandling has been used.
I want to draw a line on the image using some function in the TakeInput Class and mousehandling.
Now I see that the ViewPanel Class is showing the information of pixels as it should. but no line is
drawn on the image. Is the mousehandling of TakeInput Class is not working.

yeah, i don't like this, it's nasty, but i got it to work. try this:
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
public class Test implements MouseListener{
     public Test() {
          JFrame frame = new JFrame();
          frame.setBounds(50, 50, 200, 200);
          JComboBox cbox = new JComboBox();
          cbox.addItem("ai1");
          cbox.addItem("ai2");
          cbox.getComponent(0).addMouseListener(this);
          frame.getContentPane().add(cbox, "North");
          frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          frame.show();
     public static void main(String[] args) {
          Test testmain1 = new Test();
     public void mouseEntered(MouseEvent e) {
          System.out.println("entered");
     public void mouseReleased(MouseEvent e) {
          System.out.println("released");
     public void mousePressed(MouseEvent e) {
          System.out.println("pressed");
     public void mouseClicked(MouseEvent e) {
          System.out.println("clicked");
     public void mouseExited(MouseEvent e) {
          System.out.println("exited");
}...perhaps someone can provide a more elegant solution and/or explain why i have to do a getComponent(0), which stinks if you ask me.

Similar Messages

  • MouseListener is not working for JComboBox

    hi
    i've added a mouseListener to a JComboBox, but i don't see the messages the events should print. can anyone tell me what i've missed?
    package test;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JComboBox;
    public class testmain {
    public testmain() {
    JFrame frame = new JFrame();
    frame.setBounds(50, 50, 200, 200);
    JComboBox cbox = new JComboBox();
    cbox.addItem("ai1");
    cbox.addItem("ai2");
    cbox.addMouseListener(new MouseAdapter(){
    public void mouseReleased(MouseEvent e){
    System.out.println("released");
    public void mousePressed(MouseEvent e){
    System.out.println("pressed");
    public void mouseClicked(MouseEvent e){
    System.out.println("clicked");
    frame.getContentPane().add(cbox, "North");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.show();
    public static void main(String[] args) {
    testmain testmain1 = new testmain();
    thanks

    yeah, i don't like this, it's nasty, but i got it to work. try this:
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    public class Test implements MouseListener{
         public Test() {
              JFrame frame = new JFrame();
              frame.setBounds(50, 50, 200, 200);
              JComboBox cbox = new JComboBox();
              cbox.addItem("ai1");
              cbox.addItem("ai2");
              cbox.getComponent(0).addMouseListener(this);
              frame.getContentPane().add(cbox, "North");
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.show();
         public static void main(String[] args) {
              Test testmain1 = new Test();
         public void mouseEntered(MouseEvent e) {
              System.out.println("entered");
         public void mouseReleased(MouseEvent e) {
              System.out.println("released");
         public void mousePressed(MouseEvent e) {
              System.out.println("pressed");
         public void mouseClicked(MouseEvent e) {
              System.out.println("clicked");
         public void mouseExited(MouseEvent e) {
              System.out.println("exited");
    }...perhaps someone can provide a more elegant solution and/or explain why i have to do a getComponent(0), which stinks if you ask me.

  • Mouselistner is not working with jtable in the browser

    Hi
    I am having a problem with jTable.
    I added a mouselistener to table header to sort table but when i run that applet from my netbean ide it works fine but when i run that applet in my browser it doesn't work, i have tested, its not even generate mouseclick event .Please help me guys.
    I call this function after calling initComponents() method of JApplet.
    public void setTableAction()
    //set mouselistener to sort table on click of table header
    final JTableHeader head= jTable1.getTableHeader();
    head.addMouseListener(new java.awt.event.MouseAdapter()
    public void mouseClicked(java.awt.event.MouseEvent evt)
    Vector data= ((DefaultTableModel)jTable1.getModel ()).getDataVector();
    sortTable(data, head.columnAtPoint(evt.getPoint()));
    //set action map to change the default action performed for enter key pressed
    InputMap imap = jTable1.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke enterKey = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    KeyStroke tabKey = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    final Action oldAction= jTable1.getActionMap().get(imap.get(tabKey)); // get map to set enter key.
    imap.put(enterKey, "enter"); // set enter key
    Action newAction = new AbstractAction(){
    public void actionPerformed(ActionEvent e) {
    oldAction.actionPerformed(e);
    JTable table= (JTable)e.getSource();
    table.changeSelection(0,0,false,false);
    if(table.isCellEditable(0,0))
    String sTemp= (String)table.getValueAt(0,0);
    if(sTemp.length()>0) {
    if(bRenewItem)
    retrieveRcodeDetails("",sTemp);
    else
    processRCodeDetails(sTemp, e);
    }else
    table.editCellAt(0,0);
    jTable1.getActionMap().put("enter", newAction);
    jTable1.setPreferredScrollableViewportSize(jTable1.getPreferredSize());
    }

    Hi,
    I also am using the Bépo layout with an encrypted drive and encountered the same problem: the Return key does not work.
    It seems to work fine if you use the fr-bepo-latin9 keymap.
    # /etc/vconsole.conf
    KEYMAP=fr-bepo-latin9
    But I also looked at the files /usr/share/kbd/keymaps/i386/bepo/fr-bepo.map.gz and /usr/share/kbd/keymaps/i386/bepo/fr-bepo-latin9.map.gz (you can open gzipped files in vim directly). fr-bepo-latin9.map.gz defines keycode 28 (Return) but fr-bepo.map.gz does not.
    I modified fr-bepo.map.gz:
    # vim /usr/share/kbd/keymaps/i386/bepo/fr-bepo.map.gz # Append that line : "keycode 28 = Return".
    # mkinitcpio -p linux # Rebuild the initramfs.
    The Return key now works, but the Backspace (14, "Delete") and Shift (54) keys don’t work. I found that both the cf.map.gz (french canadian layout) and fr-bepo-latin9.map.gz files define those keycodes as well as other non-printing keys so I copied the following lines from fr-bepo-latin9.map.gz to fr-bepo.map.gz:
    keycode 1 = Escape Escape
    keycode 14 = Delete Delete
    keycode 15 = Tab Tab
    keycode 28 = Return
    keycode 29 = Control
    keycode 42 = Shift
    keycode 54 = Shift
    keycode 56 = Alt
    keycode 58 = Caps_Lock
    keycode 97 = Control
    It works! Don’t forget to rebuild the initramfs after you change the keymap file.
    # mkinitcpio -p linux
    I will send a message to the kbd and bépo projects mailing lists and report back.

  • Getting input from mouse-wheel: does not work under windows/IE

    Hi
    I have built an applet that extends JApplet. To it I have added a class that extends JPanel implements MouseListener, MouseWheelListener, MouseMotionListener.
    I collect input using the method
    public void mouseWheelMoved(MouseWheelEvent e){
    do stuff...
    I have build this on a mac and tested it in firefox and it works fine. But on xp/vista internet explorer, the applet does not respond to mousewheel input. On mac osx /safari it does not work either.
    Is there any solution to this problem?
    Best regards, Carlis.

    Just for luck, try setting the JPanel focusable.panel.setFocusable(true);If that doesn't make a difference, you need to post a [_Short, Self Contained, Compilable and Executable, Example Program (SSCCE)_|http://mindprod.com/jgloss/sscce.html] that clearly demonstrates your problem.
    db

  • KeyListener on combobox calander not working?

    Am trying to add keylistener on this combobox calander, but somehow its not working right. The calendar is added to a JTable and the keyListener on it works, when i gets focus, but when the popup is visible it looses the keylistener? Can someone help me with this?
    import com.sun.java.swing.plaf.motif.*;
    import com.sun.java.swing.plaf.windows.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.basic.*;
    import javax.swing.plaf.metal.*;
    import javax.swing.table.*;
    public class DateComboBox extends JComboBox
        public DateComboBox()
        public DateComboBox(int raekke,DefaultTableModel model,JTable tabel)
            this.raekke=raekke;
            this.model=model;
            this.tabel=tabel;
        public void setDateFormat(SimpleDateFormat dateFormat)
            this.dateFormat = dateFormat;
        public void setSelectedItem(Object item)
            // Could put extra logic here or in renderer when item is instanceof Date, Calendar, or String
            // Dont keep a list ... just the currently selected item
            removeAllItems(); // hides the popup if visible
            addItem(item);
            super.setSelectedItem(item);
        public void setText(String texte)
            setSelectedItem(texte);
        public String getText()
            return (String)this.getSelectedItem();
        public void setRaekke(int raekke)
            this.raekke=raekke;
        public void updateUI()
            ComboBoxUI cui = (ComboBoxUI) UIManager.getUI(this);
            if (cui instanceof MetalComboBoxUI)
                cui = new MetalDateComboBoxUI();
            } else if (cui instanceof MotifComboBoxUI)
                cui = new MotifDateComboBoxUI();
            } else if (cui instanceof WindowsComboBoxUI)
                cui = new WindowsDateComboBoxUI();
            setUI(cui);
        // Inner classes are used purely to keep DateComboBox component in one file
        // UI Inner classes -- one for each supported Look and Feel
        class MetalDateComboBoxUI extends MetalComboBoxUI
            protected ComboPopup createPopup()
                return new DatePopup( comboBox );
        class WindowsDateComboBoxUI extends WindowsComboBoxUI
            protected ComboPopup createPopup()
                return new DatePopup( comboBox );
        class MotifDateComboBoxUI extends MotifComboBoxUI
            protected ComboPopup createPopup()
                return new DatePopup( comboBox );
        // DatePopup inner class
        class DatePopup implements
        ComboPopup,
        MouseMotionListener,
        MouseListener,
        KeyListener,
        PopupMenuListener
            public DatePopup(JComboBox comboBox)
                this.comboBox = comboBox;
                setFocusable(true);
                addKeyListener(this);
                calendar = Calendar.getInstance();
                // check Look and Feel
                background = UIManager.getColor("ComboBox.background");
                foreground = UIManager.getColor("ComboBox.foreground");
                selectedBackground = UIManager.getColor("ComboBox.selectionBackground");
                selectedForeground = UIManager.getColor("ComboBox.selectionForeground");
                initializePopup();
            //========================================
            // begin ComboPopup method implementations
            public void show()
                try
                    // if setSelectedItem() was called with a valid date, adjust the calendar
                    calendar.setTime( dateFormat.parse( comboBox.getSelectedItem().toString() ) );
                } catch (Exception e)
                {e.printStackTrace();}
                updatePopup();
                popup.show(comboBox, 0, comboBox.getHeight());
            public void hide()
                popup.setVisible(false);
            protected JList list = new JList();
            public JList getList()
                return list;
            public MouseListener getMouseListener()
                return this;
            public MouseMotionListener getMouseMotionListener()
                return this;
            public KeyListener getKeyListener()
                return null;
            public boolean isVisible()
                return popup.isVisible();
            public void uninstallingUI()
                popup.removePopupMenuListener(this);
            // end ComboPopup method implementations
            //======================================
            //===================================================================
            // begin Event Listeners
            // MouseListener
            public void mousePressed( MouseEvent e )
            // something else registered for MousePressed
            public void mouseClicked(MouseEvent e)
            public void mouseReleased( MouseEvent e )
                if (!SwingUtilities.isLeftMouseButton(e))
                    return;
                if (!comboBox.isEnabled())
                    return;
                if (comboBox.isEditable())
                    comboBox.getEditor().getEditorComponent().requestFocus();
                else
                    comboBox.requestFocus();
                togglePopup();
            protected boolean mouseInside = false;
            public void mouseEntered(MouseEvent e)
                mouseInside = true;
            public void mouseExited(MouseEvent e)
                mouseInside = false;
            // MouseMotionListener
            public void mouseDragged(MouseEvent e)
            public void mouseMoved(MouseEvent e)
            public void keyPressed(KeyEvent e)
                if(e.getSource()==this)
                    if(e.getKeyCode()==KeyEvent.VK_CONTROL)
                        System.out.println("keytyped1");
            public void keyTyped(KeyEvent e)
            public void keyReleased( KeyEvent e )
                if(e.getKeyCode()==KeyEvent.VK_CONTROL)
                    System.out.println("keytyped2");
                if ( e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER )
                    togglePopup();
             * Variables hideNext and mouseInside are used to
             * hide the popupMenu by clicking the mouse in the JComboBox
            public void popupMenuCanceled(PopupMenuEvent e)
            protected boolean hideNext = false;
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e)
                hideNext = mouseInside;
            public void popupMenuWillBecomeVisible(PopupMenuEvent e)
            // end Event Listeners
            //=================================================================
            //===================================================================
            // begin Utility methods
            protected void togglePopup()
                if( isVisible() || hideNext)
                    hide();
                else
                    show();
                hideNext = false;
            // end Utility methods
            //=================================================================
            // Note *** did not use JButton because Popup closes when pressed
            protected JLabel createUpdateButton(final int field, final int amount)
                final JLabel label = new JLabel();
                final Border selectedBorder = new EtchedBorder();
                final Border unselectedBorder = new EmptyBorder(selectedBorder.getBorderInsets(new JLabel()));
                label.setBorder(unselectedBorder);
                label.setForeground(foreground);
                label.addMouseListener(new MouseAdapter()
                    public void mouseReleased(MouseEvent e)
                        calendar.add(field, amount);
                        updatePopup();
                    public void mouseEntered(MouseEvent e)
                        label.setBorder(selectedBorder);
                    public void mouseExited(MouseEvent e)
                        label.setBorder(unselectedBorder);
                return label;
            protected void initializePopup()
                JPanel header = new JPanel();
                header.setLayout(new BoxLayout(header, BoxLayout.X_AXIS));
                header.setBackground(background);
                header.setOpaque(true);
                JLabel label;
                label = createUpdateButton(Calendar.YEAR, -1);
                label.setText("<<");
                label.setToolTipText("Sidste �r");
                header.add(Box.createHorizontalStrut(12));
                header.add(label);
                header.add(Box.createHorizontalStrut(12));
                label = createUpdateButton(Calendar.MONTH, -1);
                label.setText("< ");
                label.setToolTipText("Sidste m�ned");
                header.add(label);
                monthLabel = new JLabel("", JLabel.CENTER);
                monthLabel.setForeground(foreground);
                header.add(Box.createHorizontalGlue());
                header.add(monthLabel);
                header.add(Box.createHorizontalGlue());
                label = createUpdateButton(Calendar.MONTH, 1);
                label.setText(" >");
                label.setToolTipText("N�ste m�ned");
                header.add(label);
                label = createUpdateButton(Calendar.YEAR, 1);
                label.setText(">>");
                label.setToolTipText("N�ste �r");
                header.add(Box.createHorizontalStrut(12));
                header.add(label);
                header.add(Box.createHorizontalStrut(12));
                popup = new JPopupMenu();
                popup.setBorder(BorderFactory.createLineBorder(Color.black));
                popup.setLayout(new BorderLayout());
                popup.setBackground(background);
                popup.addPopupMenuListener(this);
                popup.add(BorderLayout.NORTH, header);
                popup.getAccessibleContext().setAccessibleParent(comboBox);
            // update the Popup when either the month or the year of the calendar has been changed
            protected void updatePopup()
                monthLabel.setText( monthFormat.format(calendar.getTime()) );
                if (days != null)
                    popup.remove(days);
                days = new JPanel(new GridLayout(0, 7));
                days.setBackground(background);
                days.setOpaque(true);
                Calendar setupCalendar = (Calendar) calendar.clone();
                setupCalendar.set(Calendar.DAY_OF_WEEK, setupCalendar.getFirstDayOfWeek());
                for (int i = 0; i < 7; i++)
                    int dayInt = setupCalendar.get(Calendar.DAY_OF_WEEK);
                    JLabel label = new JLabel();
                    label.setHorizontalAlignment(JLabel.CENTER);
                    label.setForeground(foreground);
                    if (dayInt == Calendar.SUNDAY)
                        label.setText("s�n");
                    else if (dayInt == Calendar.MONDAY)
                        label.setText("man");
                    else if (dayInt == Calendar.TUESDAY)
                        label.setText("tir");
                    else if (dayInt == Calendar.WEDNESDAY)
                        label.setText("ons");
                    else if (dayInt == Calendar.THURSDAY)
                        label.setText("tor");
                    else if (dayInt == Calendar.FRIDAY)
                        label.setText("fre");
                    else if (dayInt == Calendar.SATURDAY)
                        label.setText("l�r");
                    //                days.add(label);
                    setupCalendar.roll(Calendar.DAY_OF_WEEK, true);
                setupCalendar = (Calendar) calendar.clone();
                setupCalendar.set(Calendar.DAY_OF_MONTH, 1);
                int first = setupCalendar.get(Calendar.DAY_OF_WEEK);
                for (int i = 0; i < (first-2) ; i++)
                    days.add(new JLabel(""));
                for (int i = 1; i <= setupCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++)
                    final int day = i;
                    final JLabel label = new JLabel(String.valueOf(day));
                    label.setHorizontalAlignment(JLabel.CENTER);
                    label.setForeground(foreground);
                    label.addMouseListener(new MouseAdapter()
                        public void mouseReleased(MouseEvent e)
                            label.setOpaque(false);
                            label.setBackground(background);
                            label.setForeground(foreground);
                            calendar.set(Calendar.DAY_OF_MONTH, day);
                            hide();
                            comboBox.requestFocus();
                            if (tabel.isEditing())
                                tabel.getCellEditor(tabel.getEditingRow(),
                                tabel.getEditingColumn()).stopCellEditing();
                            model.setValueAt(dateFormat.format(calendar.getTime()),raekke,1);
                            tabel.requestFocus();
                        public void mouseEntered(MouseEvent e)
                            label.setOpaque(true);
                            label.setBackground(selectedBackground);
                            label.setForeground(selectedForeground);
                        public void mouseExited(MouseEvent e)
                            label.setOpaque(false);
                            label.setBackground(background);
                            label.setForeground(foreground);
                    days.add(label);
                popup.add(BorderLayout.CENTER, days);
                popup.pack();
            private JComboBox comboBox;
            private Calendar calendar;
            private JPopupMenu popup;
            private JLabel monthLabel;
            private JPanel days = null;
            private SimpleDateFormat monthFormat = new SimpleDateFormat("MMM yyyy");
            //        private int antaldage=1;
            private Color selectedBackground;
            private Color selectedForeground;
            private Color background;
            private Color foreground;
        private SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
        private int raekke=-1;
        private DefaultTableModel model;
        private JTable tabel;
    }

    come on help plz....

  • Chechbox header : deselect all not working

    folks,
    I have a jtable generated from my database. IT has 3 columns . The 3rd column has checkboxes in it. I am implementing a "CHECK ALL"
    checkbox on the header for selection and deselection of checkboxes. the below code works for selection of all boxes.. IT DOES NOT
    WORK WHEN IT IS DESELECTED ? i want to make it work for deselection also
    I call the custom table renderer from main program as follows :
    tc = table.getColumnModel().getColumn(3);
    tc.setHeaderRenderer(new CustomTableCellRenderer1(new MyItemListener(),Name));
    this is item listner in main program for checkbox "check all" present in the table header :
    class MyItemListener implements ItemListener
    public void itemStateChanged(ItemEvent e) {
    Object source = e.getSource();
    if (source instanceof AbstractButton == false) return;
    boolean checked=e.getStateChange() == ItemEvent.SELECTED;
    for(int x = 0, y = table.getRowCount(); x < y; x++)
    table.setValueAt(new Boolean(checked),x,3);
    if (e.getStateChange() == ItemEvent.DESELECTED) // dosent work
    System.out.println("deselect all"); // may b code for deselection
    this is CustomTableCellRenderer1 class below:
    package moxaclient;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    class CustomTableCellRenderer1 extends JCheckBox
    implements TableCellRenderer, MouseListener {
    private static final long serialVersionUID = 1L;
    protected CustomTableCellRenderer1 rendererComponent;
    protected int column;
    String Name;
    private JTable table1;
    Object abc=null;
    protected boolean mousePressed = false;
    public CustomTableCellRenderer1(ItemListener itemListener,String name) {
    rendererComponent = this;
    rendererComponent.addItemListener(itemListener);
    this.Name=name;
    public Component getTableCellRendererComponent(
    JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
    if (table != null) {
    JTableHeader header = table.getTableHeader();
    this.table1=table;
    if (header != null) {
    rendererComponent.setForeground(header.getForegrou nd());
    rendererComponent.setBackground(header.getBackgrou nd());
    rendererComponent.setFont(header.getFont());
    header.addMouseListener(rendererComponent);
    setColumn(column);
    rendererComponent.setText("Check All");
    setBorder(UIManager.getBorder("TableHeader.cellBor der"));
    return rendererComponent;
    protected void setColumn(int column) {
    this.column = column;
    public int getColumn() {
    return column;
    protected void handleClickEvent(MouseEvent e) {
    if (mousePressed) {
    mousePressed=false;
    JTableHeader header = (JTableHeader)(e.getSource());
    JTable tableView = header.getTable();
    TableColumnModel columnModel = tableView.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int column = tableView.convertColumnIndexToModel(viewColumn);
    if (viewColumn == this.column && e.getClickCount() == 1 && column != -1) {
    doClick();
    int row=table1.getRowCount();
    if(row!=0)
    for(int i=0;i<=row-1;i++)
    String Sensor =(String) table1.getValueAt(i, column-3); // // when checkbox selectedthis code gets all value present in table and stores in string abc
    Double Value =(Double) table1.getValueAt(i, column-2);
    String Date =(String) table1.getValueAt(i, column-1);
    abc += Sensor+"\t"+Value+"\t"+Name+"\t"+Date+"\t";
    public void mouseClicked(MouseEvent e) {
    handleClickEvent(e);
    ((JTableHeader)e.getSource()).repaint();
    public void mousePressed(MouseEvent e) {
    mousePressed = true;
    public void mouseReleased(MouseEvent e) {
    public void mouseEntered(MouseEvent e) {
    public void mouseExited(MouseEvent e) {
    plzz help.

    please add tags around the code in your posts.
    Dinud123 wrote:
    IT DOES NOT
    WORK WHEN IT IS DESELECTED ? i want to make it work for deselection alsoI don't know any user interface where I would toggle "select all" and "deselect all" via the same control. That may be for a reason.
    So my suggestion is: provide a second button for "deselect all".
    bye
    TPD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Code not working... again :P

    This is my 'paddle' game. You bounce a ball around the around the screen, and it's all working. I'm on the final part, which is what happens when you miss the ball (it goes off the left side of the screen). I'd like to print out a message to the middle of my screen saying "Press R to Reset", while the ball is not anywhere to be seen on the screen (is there a way I can get it to stop moving? my method right now is just to place it far away off screen, which just doesn't seem very professional to me). I made an if statement that should control this, but it's not working (when the you miss the ball, it disappears but nothing prints to the screen, and pressing R doesn't do anything either ) .
    To skip quickly to the if statement just use the find option in your browser and put in 'PROBLEM'
    This is all written in an applet.
    This is my code:
    int width, height, x, ypaddle, xball = 1, yball = 1, xctrl = 1, yctrl = 1, speed = 5, scorekeeper = 0, startkeeper = 0, keykeeper;
        Graphics g;
        String startagain;
        char move;
        Thread run;
        private Random random = new Random ();
        int ballstart = random.nextInt (400);
         *Initializes variables
        public void init ()
            resize (700, 500);
            setBackground (Color.white);
            addKeyListener (this);
            addMouseListener (this);
            addMouseMotionListener (this);
            run = new Thread (this);
            run.start ();
            startagain = "To Reset Press R";
            xball = ballstart;
            yball = ballstart;
        public void run ()
            while (true)
                try
                    run.sleep (50);
                    if (xctrl == 1 && startkeeper == 0)
                        xball = xball + speed;
                    if (yctrl == 1 && startkeeper == 0)
                        yball = yball + speed;
                    if (xctrl == 0 && startkeeper == 0)
                        xball = xball - speed;
                    if (yctrl == 0 && startkeeper == 0)
                        yball = yball - speed;
                    if (xball + 50 >= 660 && startkeeper == 0)
                        xball = xball - speed;
                        xctrl = 0;
                    if ((xball + 50) < 15 && yball <= ypaddle + 50 && yball >= ypaddle - 70 && startkeeper == 0)
                        xball = xball + speed;
                        xctrl = 1;
                    if (yball + 50 >= 460 && startkeeper == 0)
                        yball = yball - speed;
                        yctrl = 0;
                    if (yball + 50 <= 35 && startkeeper == 0)
                        yball = yball + speed;
                        yctrl = 1;
    //PROBLEM BELOW
                    if (xball + 50 <= 0 && startkeeper == 0)
                        if (xball + 50 <= 0)
                            yball = -100;
                            xball = -100;
                            repaint ();
                            g.drawString (startagain, 300, 300);
                        if (xball + 50 <= 0 && startkeeper == 1)
                            scorekeeper = scorekeeper + 1;
                            xball = ballstart;
                            yball = ballstart;
                            startkeeper = 0;
                    repaint ();
                catch (Exception e)
        public void keyPressed (KeyEvent e)
            keykeeper = e.getKeyChar ();
            if (keykeeper == 'r')
                startkeeper = 1;
                keykeeper = 'x';
        }

    For a public Usenet forum, most readers will stop reading by 20Kb, and start complaining at 30Kb.
    lol, I have a long way to go before i make programs that big :P
    By incompatible snippet, do you mean I should post the whole thing? Here it is:
    // The "Ping" class.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;
    *Ping
    *@author Lenny
    public class Ping extends Applet
        implements KeyListener, MouseListener, MouseMotionListener, Runnable
        int width, height, x, ypaddle, xball = 1, yball = 1, xctrl = 1, yctrl = 1, speed = 5, scorekeeper = 0, startkeeper = 0, keykeeper;
        Graphics g;
        String startagain;
        char move;
        Thread run;
        private Random random = new Random ();
        int ballstart = random.nextInt (400);
         *Initializes variables
        public void init ()
            resize (700, 500);
            setBackground (Color.white);
            addKeyListener (this);
            addMouseListener (this);
            addMouseMotionListener (this);
            run = new Thread (this);
            run.start ();
            startagain = "To Reset Press R";
            xball = ballstart;
            yball = ballstart;
        public void run ()
            while (true)
                try
                    run.sleep (50);
                    if (xctrl == 1 && startkeeper == 0)
                        xball = xball + speed;
                    if (yctrl == 1 && startkeeper == 0)
                        yball = yball + speed;
                    if (xctrl == 0 && startkeeper == 0)
                        xball = xball - speed;
                    if (yctrl == 0 && startkeeper == 0)
                        yball = yball - speed;
                    if (xball + 50 >= 660 && startkeeper == 0)
                        xball = xball - speed;
                        xctrl = 0;
                    if ((xball + 50) < 15 && yball <= ypaddle + 50 && yball >= ypaddle - 70 && startkeeper == 0)
                        xball = xball + speed;
                        xctrl = 1;
                    if (yball + 50 >= 460 && startkeeper == 0)
                        yball = yball - speed;
                        yctrl = 0;
                    if (yball + 50 <= 35 && startkeeper == 0)
                        yball = yball + speed;
                        yctrl = 1;
    //PROBLEM HERE
                    if (xball + 50 <= 0 && startkeeper == 0)
                        if (xball + 50 <= 0)
                            yball = -100;
                            xball = -100;
                            repaint ();
                            g.drawString (startagain, 300, 300);
                        if (xball + 50 <= 0 && startkeeper == 1)
                            scorekeeper = scorekeeper + 1;
                            xball = ballstart;
                            yball = ballstart;
                            startkeeper = 0;
                    repaint ();
                catch (Exception e)
        public void keyPressed (KeyEvent e)
            keykeeper = e.getKeyChar ();
            if (keykeeper == 'r')
                startkeeper = 1;
                keykeeper = 'x';
        public void keyReleased (KeyEvent e)
        public void keyTyped (KeyEvent e)
        public void mouseEntered (MouseEvent e)
        public void mouseExited (MouseEvent e)
        public void mousePressed (MouseEvent e)
        public void mouseReleased (MouseEvent e)
        public void mouseClicked (MouseEvent e)
        public void mouseMoved (MouseEvent e)
            ypaddle = e.getY ();
            repaint ();
        public void mouseDragged (MouseEvent e)
        public void paint (Graphics g)
            paddle (g, ypaddle);
            walls (g);
            //enemies (g);
            ball (g);
         * Creates the paddle for hitting the ball
         *@param    y   value used to move the paddle vertically
        public void paddle (Graphics g, int y)
            g.fillRect (10, y - 25, 15, 70);
         *Creates the walls for the ball to bounce off of.
        public void walls (Graphics g)
            g.setColor (Color.yellow);
            g.fillRect (25, 10, 675, 25);
            g.setColor (Color.red);
            g.fillRect (675, 10, 25, 475);
            g.setColor (Color.cyan);
            g.fillRect (25, 475, 675, 25);
         *Creates the enemies to avoid.
        public void enemies (Graphics g)
            int place1 = random.nextInt (1000);
            int place1a = random.nextInt (1000);
            int place2 = random.nextInt (1000);
            int place2a = random.nextInt (1000);
            g.setColor (Color.black);
            g.fillOval (place1, place1a, 10, 10);
        public void ball (Graphics g)
            g.setColor (Color.black);
            g.fillRect (xball + 50, yball + 50, 20, 20);
            g.setColor (Color.white);
            g.fillRect (xball + 53, yball + 55, 5, 5);
            g.fillRect (xball + 63, yball + 55, 5, 5);
            g.fillRect (xball + 56, yball + 63, 9, 5);
    } // Ping classEdited by: soundweave on Jan 16, 2010 7:54 PM

  • Code not working, anyone know why?

    I'm making a simple pong game, and it's important to me that I use JAVA as efficient as possible (that is, use object orientated stuff, mostly). So, for drawing the ball and the players, I had thought up the following steps:
    - the applet has an array list that contains drawables*
    - if the ball and players need to be drawn, the applet uses a for-each loop, wich will call the draw(Graphics g) of all the drawables in the array list.
    * interface, guarantees that the method public void draw(Graphics g) is pressent.
    This is how I programmed it:
    http://willhostforfood.com/access.php?fileid=32821
    Only problem is, it doesn't work. The method paint() of the applet should result in "Hello World" being drawn on the screen (I know this seems like an eleborate method, but using seperate objects will help organise things once I have like, 20 - 30 balls on screen), but it doesn't.
    Does anyone know why it is not working?

    Here ya go, this is something I did quite a while ago, knock yourself out:
    package RandomColor;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Cursor;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.awt.Image;
    import java.awt.image.MemoryImageSource;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.awt.Point;
    import java.awt.Toolkit;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.util.Random;
    public class RandomColor extends JFrame implements MouseListener, MouseMotionListener, MouseWheelListener{
      private BufferedImage myImage = null;
      private Canvas myCanvas = null;
      private Color bgColor = Color.BLACK;
      public RandomColor() throws java.lang.Exception {
        super();
        setUndecorated(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setBackground(bgColor);
        Dimension myDimension = Toolkit.getDefaultToolkit().getScreenSize();
        setSize(myDimension);
        setMinimumSize(myDimension);
        JPanel myJP = new JPanel();
        myJP.setBackground(bgColor);
        Dimension dImage = new Dimension(this.getAccessibleContext().getAccessibleComponent().getSize());
        myCanvas = new Canvas();
        myCanvas.addMouseListener(this);
        myCanvas.addMouseMotionListener(this);
        myCanvas.addMouseWheelListener(this);
        myCanvas.setSize(dImage.width, dImage.height);
        myJP.add(myCanvas);
        add(myJP);
    // start of code to hide the cursor   
        int[] pixels = new int[16 * 16];
        Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
        Cursor transparentCursor = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0), "invisiblecursor");
        getContentPane().setCursor(transparentCursor);
    // end of code to hide cursor   
        pack();
        setVisible(true);
        Random myR = new Random();
        myImage = new BufferedImage((int) (dImage.getWidth()+0.99), (int) (dImage.getHeight()+0.99), BufferedImage.TYPE_INT_RGB);
        int i = myImage.getWidth();
        int j = myImage.getHeight();
        Ball[] myBall = {new Ball(), new Ball(), new Ball()};
        for (int k=0; k<myBall.length; k++){
          myBall[k].setBackGroundColor(Color.BLACK);
          myBall[k].setBounds(0, i, 0, j);
          myBall[k].setRandomColor(true);
          myBall[k].setLocation(myR.nextInt(i), myR.nextInt(j));
          myBall[k].setMoveRate(32, 32, 1, 1, true);
          myBall[k].setSize( 289, 167);
        Graphics g = myImage.getGraphics();
        while(true) {
          for (int k=0; k<myBall.length; k++){
            g.setColor(myBall[k].fgColor);
            g.fillOval(myBall[k].x, myBall[k].y, myBall[k].width, myBall[k].height);
          invalidate();
          paint(getGraphics());
          for (int k=0; k<myBall.length; k++){
            g.setColor(myBall[k].bgColor);
            g.fillOval(myBall[k].x, myBall[k].y, myBall[k].width, myBall[k].height);
            myBall[k].move();
      public void mouseClicked(MouseEvent e){
        exit();
      public void mouseDragged(MouseEvent e){
    //    exit();
      public void mouseEntered(MouseEvent e){
    //    exit();
      public void mouseExited(MouseEvent e){
    //    exit();
      public void mouseMoved(MouseEvent e){
    //    exit();
      public void mousePressed(MouseEvent e){
        exit();
      public void mouseReleased(MouseEvent e){
        exit();
      public void mouseWheelMoved(MouseWheelEvent e){
        exit();
      private void exit(){
        System.exit(0);
      public void paint(Graphics g){
        super.paint(g);
        myCanvas.getGraphics().drawImage(myImage, 0, 0, null);
      public static void main(String[] args) throws java.lang.Exception {
        new RandomColor();
        System.out.println("Done -- RandomColor");
    }Ball Class:
    package RandomColor;
    import java.awt.Color;
    import java.util.Random;
    public class Ball {
      private int iLeft      = 0;
      private int iRight     = 0;
      private int iTop       = 0;
      private int iBottom    = 0;
      private int moveX      = 1;
      private int moveY      = 1;
      private int xScale     = moveX;
      private int yScale     = moveY;
      private int xDirection = 1;
      private int yDirection = 1;
      private boolean moveRandom = false;
      private boolean colorRandom = false;
      private Random myRand = null;
      public Color fgColor = Color.BLACK;
      public Color bgColor = Color.BLACK;
      public int x = 0;
      public int y = 0; 
      public int width  = 1;
      public int height = 1;
      public Ball(){
        myRand = new Random();
        setRandomColor(colorRandom);
      public void move(){
        x = 5 + x + (xScale*xDirection);
        y = 5 + y + (yScale*yDirection);
        if(x<=iLeft){
          x = 0;
          if(moveRandom) xScale = myRand.nextInt(moveX);else xScale = moveX;
          xDirection *= (-1);
          if(colorRandom) setRandomColor(colorRandom);
        if(x>=iRight-width){
          x = iRight-width;
          if(moveRandom) xScale = myRand.nextInt(moveX);else xScale = moveX;
          xDirection *= (-1);
          if(colorRandom) setRandomColor(colorRandom);
        if(y<=iTop){
          y = 0;
          if(moveRandom) yScale = myRand.nextInt(moveY);else xScale = moveY;
          yDirection *= (-1);
          if(colorRandom) setRandomColor(colorRandom);
        if(y>=iBottom-height){
          y = iBottom-height;
          if(moveRandom) yScale = myRand.nextInt(moveY);else xScale = moveY;
          yDirection *= (-1);
          if(colorRandom) setRandomColor(colorRandom);
      public void setColor(Color c){
        fgColor = c;
      public void setBackGroundColor(Color c){
        bgColor = c;
      public void setBounds(int Left, int Right, int Top, int Bottom){
        iLeft   = Left;
        iRight  = Right;
        iTop    = Top;
        iBottom = Bottom;
      public void setLocation(int x, int y){
        this.x = x;
        this.y = y;
      public void setMoveRate(int xMove, int yMove, int xDir, int yDir, boolean randMove){
        moveX       = xMove;
        moveY       = yMove;
        moveRandom  = randMove;
        xDirection  = xDir;
        yDirection  = yDir;
      public void setRandomColor(boolean random){
        colorRandom = random;
        switch (myRand.nextInt(3)+1){
          case 1:  fgColor = Color.BLUE;
                   break;
          case 2:  fgColor = Color.GREEN;
                   break;
          case 3:  fgColor = Color.RED;
                   break;
          default: fgColor = Color.BLACK;
                   break;
      public void setSize(int width, int height){
        this.width  = width;
        this.height = height;
    }

  • Application is fine in prompt line but in the JSW does not work

    Hi folks
    I have a stuck problem with my application. It works fine with java ... but does not work with the javaws! The problem is in a inner class who extends a panel which must be painted several times (the application works with a optimazation traffic algorithm)... If i use the inner class, the program does not appear and there is no bug messages.
    If a cut the lines with the drawingPane code, the application run without a problem with the javaws!
    These are the important lines of the code:
    // Main class
    public class AlgConstrutivos extends JPanel
    implements MouseListener, ActionListener{
    // The problem PANEL!!!!!!!!!!
    private JPanel drawingPane;
    // The constructor of main class
    public AlgConstrutivos() {
    drawingPane = new DrawingPane();
    drawingPane.setBackground(Color.white);
    drawingPane.addMouseListener(this);
    //Put the drawing area in a scroll pane.
    JScrollPane scroller = new JScrollPane(drawingPane);
    scroller.setPreferredSize(new Dimension(400,400));
    //Lay out
    add(ordem, BorderLayout.PAGE_START);
    add(scroller, BorderLayout.CENTER);
    // The main function
    public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    JComponent newContentPane = new AlgConstrutivos();
    newContentPane.setOpaque(true);
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public class DrawingPane extends JPanel {
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    // Draw some lines and points...
    Any help?
    Thanks...
    Andre Cordenonsi

    Yes... In fact, the inner class is in the same .java file...
    There are no error messages at all!
    My jnpl file is (i run with --> javaws a.jnpl)
    <?xml version="1.0" encoding="UTF-8"?>
    <jnlp spec="1.0+"
    codebase="file:///c:/animacao/" href="a.jnlp"
    >
    <information>
    <title>ARGH!</title>
    <vendor>Myself</vendor>
    <homepage href="/animacao" />
    <description>...</description>
    </information>
    <offline-allowed/>
    <security>
    <all-permissions/>
    </security>
    <resources>
    <j2se version="1.2+" />
    <jar href="Teste.jar"/>
    <nativelib href="Teste.jar"/>
    </resources>
    <application-desc main-class="AlgConstrutivos" />
    </jnlp>
    I try use the nativelib resource, but nothing happens...
    Andre Cordenonsi

  • Not work tablet UI on Prestigio 5080 PRO tablet

    I read that browser.ui.layout.tablet = "1" can fix this problem. But it not works. I can work only in pnone interface that is not good for my 8'' tablet.

    Would it be possible for you to share the problematic pdf and OS information  with us at [email protected] so that we may investigate?
    Thanks,
    Adobe Reader Team

  • Why self-defined access sequences of free goods can not work?

    Hi gurus,
    I have maintained access sequences of free goods self-defined.but when i creat the SO it does not work!
    when i used the standard access sequences ,it is OK .
    Can anybody tell me why?
    thanks in advance

    Dear Sandy,
    Go to V/N1 transaction select your self defined access sequence then go in to the accesses and fields and check all fields are activated.
    Make sure that these fields are flowing in your sales order.
    I hope this will help you,
    Regards,
    Murali.

  • Adobe bridge raw not working with windows vista in photoshop cc, why?

    adobe bridge raw not working in photoshop cc, is there a fix?

    Your sure your using photoshop cc on windows vista?
    I was under the impression that photoshop cc would not even install on windows vista.
    What version of camera raw do you have?
    In photoshop under Help>About Plugin does it list Camera Raw and if so which version is it?
    (click on the words Camera Raw to see the version)
    Camera raw doesn't work if it's a camera raw file or some other file type such as jpeg or tif?
    What camera are the camera raw files from?
    Officially camera raw 8.3 is the latest version of camera raw that will work on windows vista.

  • Adobe Bridge CS5 in windows 7 not working?

    Adobe Bridge CS5 in windows 7 not working. I was using bridge perfectly for last 2 years. It stops working since 3 days. I tried to install updates. Showing some error to install.
    Tried to install creative cloud..again some error. Error code : 82
    Could you please advice how I can fix my adobe bridge.

    https://www.youtube.com/watch?v=xDYpTOoV81Q&feature=youtu.be
    please check this video I uploaded..this is what happens when I click adobe bridge.. just blinks and go off. bridge not working on task manager

  • ADOBE CLOUD ON MY DESKTOP WILL NOT WORK. IT LOADS UP BUT NOTHING FILLS THE WINDOW

    ADOBE CLOUD ON MY DESKTOP WILL NOT WORK. IT LOADS UP BUT NOTHING FILLS THE WINDOW

    BLANK Cloud Screen http://forums.adobe.com/message/5484303 may help
    -and step by step http://forums.adobe.com/thread/1440508?tstart=0
    -and http://helpx.adobe.com/creative-cloud/kb/blank-white-screen-ccp.html

  • Partner application logoff not working

    We have a partner application registered with sso with custom login screen. The login works fine. We use the following code to logoff the partner application in logoff.jsp
    response.setHeader("Osso-Return-Url", "http://my.oracle.com" );
    response.sendError(470, "Oracle SSO");
    session.invalidate();
    but the logoff is not working properly. It is not invalidating the session and the logout http request is not going from the application server to the sso server.
    Are there any additional configurations for SSO logoff.Any help is appreciated.
    Thanks

    Hi
    The WF should also trigger if i add the Partner function in UI.If i change any Attribute the WF triggers but i dont want to change the attribute when i add the partner function.
    If i have only one event for WF that is Partner Change the WF will not trigger it for the 1st time when i save the UI. But next i come to the same saved doc and add a partner function then the Wf triggers.
    So this means that Partner change is active.
    the issue here is i need to trigger the WF on , the 1st time i save the UI, for which i wil be using Attribute Change and next time when i come back to saved doc the and add only the partner function and no changes are made to attributes the WF should again trigger.
    Thanks
    Tarmeem

Maybe you are looking for

  • Can i use the same itunes account for 2 iphones?

    CAN YOU USE 2 IPHONES WITH 1 ITUNES ACCT?

  • Logging in to another user in B1

    Hello Guys   Iam using SAP B1 2004 2B PL:40,(India)   When iam trying to enter with another userID according to the Authorizations, When i Logged in to that, iam not able to open any document & getting a message "Generating this document requires num

  • SLT Scenario in question: ECC - SLT- HANA DB

    Hello Team, Issue : I need propose a scenario where we need to recover the data in a table in case of any failure occurs (where point in time recovery is not possible) or there is mismatch in Target database (HANA) when compared to ECC source system.

  • Xcode Continuous integration - latestRunSubStatus = internal-credential-server-error

    Greetings. I have been trying to make continuous integration build using Bots with Xcode 5.1(5B130a) from Xcode server (3.1.1). The SCM is configured with external svn repository, which am able to successfully browse from safari. Am trying to make in

  • Printer using in Smartforms

    Hi, I have the job to change all old sapscript orders to be printed with co01/02/03 from DIN A4 to DIN A5 and decided to recreate them in smartforms now. The boxes and stuff were created dynamically and to change that big forms and printprograms in s