problem of MouseListener interface




I'm developing a dialog for that I've written a class.
In that class I've to implement an interface MouseListener but dont want to implement all method.
but I have already extended one class JDialog.

Is there any way to not to implement all method

Posted On: Wednesday 17th of October 2012 09:22:25 PM Total Views:  194
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




problem in getPosition and setPosition......

Cpoint.java import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Cpoint extends JPanel implements Runnable{ int x =400; int y = 25; int dx = 4; int dy = 1; int radius = 20; Cpoint() { Thread thread = new Thread(this); thread.start(); } /*public void setPosition(int x) { this.x = x; }*/ public int getPosition() { return x; } public void run() { // TODO Auto-generated method stub while(true) { if(x+dx>this.getWidth()-radius) { x = this.getWidth()-radius-1; dx = -dx; } else if(x + dx < 0+radius) { x = 0+radius; dx = -dx; } else { x+=dx; } if(y+dy>this.getHeight()-radius) { y = this.getHeight()-radius-1; dy = -dy; } else if(y + dy < 0+radius) { y = 0+radius; dy = -dy; } else { y+=dy; } x+=dx; repaint(); try { Thread.sleep(17); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.BLUE); g.fillOval(x-radius, y-radius, radius*2,radius*2); System.out.println(this.getPosition()); } }
VIEWS ON THIS POST

105

Posted on:

Wednesday 3rd October 2012
View Replies!

MouseListener events problem

at the start say b=true and a=false; private void addMouseEvents(Graphics g) { this.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if(a){ } if(b){ a=true; } } }
VIEWS ON THIS POST

163

Posted on:

Wednesday 3rd October 2012
View Replies!

problem in ActionListener

i am having problem in this actionlistner while running first time it get called once and next time it called twice then four times and so on here is code please give me any solution thank you very much public void launch() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:cone"); try { Statement st=con.createStatement(); String str="SELECT * FROM quizcontest"; ResultSet rs=st.executeQuery(str); while(rs.next()) { id[i]=rs.getInt("id"); ques[i]=rs.getString("ques"); a[i]=rs.getString("a"); b[i]=rs.getString("b"); c[i]=rs.getString("c"); d[i]=rs.getString("d"); cor[i]=rs.getString("cor"); //System.out.println(" "+id[i]+" "+ques[i]+" "+a[i]+" "+b[i]+" "+c[i]+" "+d[i]); i++; } i--; con.close(); } catch(SQLException e) { System.out.println("Table creation process denied");} } catch(Exception e) { e.printStackTrace(); } } public void display() { // System.out.println("value of g in display="+g+"\n\n"); if(g
VIEWS ON THIS POST

113

Posted on:

Wednesday 3rd October 2012
View Replies!

problem in erasing panel

hey i am new in java n getting this problem i want to create a program in which i am retrieving data from database and showing in gui frame but i want when submit pressed old frame's data should be get erased but instead of that it appends in that thank you for your help package javaapplication48; import java.awt.BorderLayout; import java.io.*; import java.sql.*; import javax.swing.*; import java.awt.event.*; public class JavaApplication48 implements ActionListener { private JFrame f1,f2; ResultSet rs; private JPanel p1,p2,p3,p4,p5; private JLabel l1,l2; private JRadioButton r1,r2,r3,r4; private JButton b1; public int id,i=1; private String ques,a,b,c,d,cor; Box b2=Box.createVerticalBox(); public JavaApplication48() { f1=new JFrame("eww"); f2=new JFrame("result"); b1=new JButton("Submit"); } public void launch() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:cone"); try { Statement st=con.createStatement(); String str="SELECT * FROM quizcontest where id="+i; rs=st.executeQuery(str); while(rs.next()) { id=rs.getInt("id"); ques=rs.getString("ques"); a=rs.getString("a"); b=rs.getString("b"); c=rs.getString("c"); d=rs.getString("d"); cor=rs.getString("cor"); } con.close(); } catch(SQLException e) { System.out.println("Table creation process denied");} } catch(Exception e) { e.printStackTrace(); } p1=new JPanel(); p2=new JPanel(); p3=new JPanel(); p4=new JPanel(); p5=new JPanel(); l1=new JLabel(ques); r1=new JRadioButton(a); r2=new JRadioButton(b); r3=new JRadioButton(c); r4=new JRadioButton(d); p1.add(l1); b2.add(p1); p2.add(r1); p2.add(r2); b2.add(p2); p3.add(r3); p3.add(r4); b2.add(p3); p4.add(b1); b2.add(p4); f1.add(b2,BorderLayout.CENTER); f1.setSize(400,400); //f1.pack(); f1.setVisible(true); b1.addActionListener(this); } // @Override public void actionPerformed(ActionEvent e) { f1.dispose(); i++; launch(); } public static void main(String[] args) { JavaApplication48 ob=new JavaApplication48(); ob.launch(); } }
VIEWS ON THIS POST

128

Posted on:

Wednesday 3rd October 2012
View Replies!

problem in actionlistner

i am having problem in this actionlistner while running first time it get called once and next time it called twice then four times and so on here is code please give me any solution thank you very much public void launch() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:cone"); try { Statement st=con.createStatement(); String str="SELECT * FROM quizcontest"; ResultSet rs=st.executeQuery(str); while(rs.next()) { id[i]=rs.getInt("id"); ques[i]=rs.getString("ques"); a[i]=rs.getString("a"); b[i]=rs.getString("b"); c[i]=rs.getString("c"); d[i]=rs.getString("d"); cor[i]=rs.getString("cor"); //System.out.println(" "+id[i]+" "+ques[i]+" "+a[i]+" "+b[i]+" "+c[i]+" "+d[i]); i++; } i--; con.close(); } catch(SQLException e) { System.out.println("Table creation process denied");} } catch(Exception e) { e.printStackTrace(); } } public void display() { // System.out.println("value of g in display="+g+"\n\n"); if(g
VIEWS ON THIS POST

165

Posted on:

Wednesday 3rd October 2012
View Replies!

problem in actionlistner

i am having problem in this actionlistner while running first time it get called once and next time it called twice then four times and so on here is code please give me any solution thank you very much public void launch() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:cone"); try { Statement st=con.createStatement(); String str="SELECT * FROM quizcontest"; ResultSet rs=st.executeQuery(str); while(rs.next()) { id[i]=rs.getInt("id"); ques[i]=rs.getString("ques"); a[i]=rs.getString("a"); b[i]=rs.getString("b"); c[i]=rs.getString("c"); d[i]=rs.getString("d"); cor[i]=rs.getString("cor"); //System.out.println(" "+id[i]+" "+ques[i]+" "+a[i]+" "+b[i]+" "+c[i]+" "+d[i]); i++; } i--; con.close(); } catch(SQLException e) { System.out.println("Table creation process denied");} } catch(Exception e) { e.printStackTrace(); } } public void display() { // System.out.println("value of g in display="+g+"\n\n"); if(g
VIEWS ON THIS POST

164

Posted on:

Wednesday 3rd October 2012
View Replies!

problem with jcombobox

hey you all, i have combobox with big list and when i drag the list back and forth the list get messed up. what i have to do in order to avoid this
VIEWS ON THIS POST

115

Posted on:

Tuesday 16th October 2012
View Replies!

button problem

hi, help me with this code.... import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; public class EventDemo implements ActionListener{ JButton b1; void go(){ JFrame frame=new JFrame("my first applet"); b1=new JButton("my buttton"); b1.setName("click"); b1.setText("click me"); b1.addActionListener(this); frame.add(b1); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 200); frame.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { b1.setText("you clicked me"); } public static void main(String[] args) { EventDemo test=new EventDemo(); test.go(); } }
VIEWS ON THIS POST

89

Posted on:

Wednesday 17th October 2012
View Replies!

Modal dialog problem with JApplet

Hi , When i make a JDialog modal, it only gets modal with respect to my JApplet only, but i want to make it modal with respect to browser. like the usual modal dialogs which can be made using javascript. Is there any way to make a JDialog modal with respect to browser. Any hints or answer would help me a lot.
VIEWS ON THIS POST

146

Posted on:

Wednesday 17th October 2012
View Replies!

problem in attached file .

Help me out in solving 1 error in my code: /* please run this code and try to sort out the error.*/ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.*; import java.util.Enumeration; import java.util.zip.*; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; public class Zip extends JPanel implements ActionListener { JButton button1, button2, button3; JFileChooser chooser; String choosertitle; JTextField field1, field2; //private int BUFFER; static final int BUFFER = 2048; public Zip() { this.setLayout(null); button1 = new JButton("Browse"); button2 = new JButton("Browse"); button3 = new JButton("Zip"); field1 = new JTextField(); field2 = new JTextField(); field1.setBounds(30, 50, 200, 25); button1.setBounds(240, 50, 100, 25); this.add(field1); this.add(button1); field2.setBounds(30, 150, 200, 25); button2.setBounds(240, 150, 100, 25); this.add(field2); this.add(button2); button1.addActionListener(this); add(button1); button2.addActionListener(this); add(button2); button3.setBounds(30, 200, 90, 25); this.add(button3); button3.addActionListener(this); add(button3); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1actionPerformed(e); } }); button2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button2ActionPerformed(e); } }); button3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button3ActionPerformed(e); } }); } public void unzip(String argv){ try { BufferedOutputStream dest = null; BufferedInputStream is = null; ZipEntry entry; ZipFile zipfile = new ZipFile(argv); Enumeration e = zipfile.entries(); while(e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); System.out.println("Extracting: " +entry); is = new BufferedInputStream (zipfile.getInputStream(entry)); int count; byte data[] = new byte[BUFFER]; FileOutputStream fos = new FileOutputStream(entry.getName()); dest = new BufferedOutputStream(fos, BUFFER); while ((count = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); is.close(); } } catch(Exception e) { e.printStackTrace(); } } public void button2ActionPerformed(java.awt.event.ActionEvent e) { int result; /* Chooser frame=new Chooser(); field2.setText(frame.fileName1);*/ chooser = new JFileChooser(); //chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle(choosertitle); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // // disable the " files" option. // chooser.setAcceptFileFilterUsed(false); // if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); field2.setText(chooser.getSelectedFile().toString()); } else { System.out.println("No Selection "); } } public void button1actionPerformed(java.awt.event.ActionEvent e) { int result; /* Chooser frame=new Chooser(); field2.setText(frame.fileName1);*/ chooser = new JFileChooser(); //chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle(choosertitle); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // // disable the " files" option. // chooser.setAcceptFileFilterUsed(false); // if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); field1.setText(chooser.getSelectedFile().toString()); } else { System.out.println("No Selection "); } } public void button3ActionPerformed(java.awt.event.ActionEvent evt) { this.zip (field1.getText()) ; } /* private void zip(String argv[]) { try { BufferedInputStream origin = null; FileOutputStream dest = new FileOutputStream("c.zip"); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); //out.setMethod(ZipOutputStream.DEFLATED); byte data[] = new byte[BUFFER]; // get a list of files from current directory File f = new File("."); String files[] = f.list(); for (int i=0; i
VIEWS ON THIS POST

155

Posted on:

Wednesday 17th October 2012
View Replies!

getting a problem ,can't see the button

hi , i was testing out card layout. What i want in my application is three panels At first i want the frame to be Divided into two panels and then add buttons on it . This is where the problem is coming. The button is not visible on the panel . It is visible when i remove the second panel . Another question is that can i control the size of the button on it here's the full code : import java.awt.event.*; import java.awt.*; public class CardLayoutEg extends Frame { public static void main(String... args) { CardLayoutEg cd=new CardLayoutEg(); cd.setVisible(true); } private Panel p1,first,second,third; Button b1; CardLayoutEg() { setSize(700,800); p1=new Panel(); Checkbox c1=new Checkbox("wierd"); b1=new Button("next"); b1.setBounds(40,50,200,100); p1=new Panel(); p1.setLayout(null); first=new Panel(); second=new Panel(); third=new Panel(); first.add(c1); first.add(b1); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CardLayout c=(CardLayout)p1.getLayout(); c.next(p1); } }); p1.setSize(700,600); third.setSize(700,200); p1.setLayout(new CardLayout()); p1.add(first,"1"); p1.add(second,"2"); first.setBackground(Color.green); second.setBackground(Color.red); add(p1); add(third); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } }
VIEWS ON THIS POST

167

Posted on:

Wednesday 17th October 2012
View Replies!

Scroll panel problems

I am having alot of problems getting this scroll panel to work. Specifically I have the [panel on my GUI, but I cant figure out how to get the text area to populate it. Can someone please tell me what I a,m doing wrong here. These are the code portions that pertain to the scroll panel only. private JTextArea jtextarea1;//define textarea private JScrollPane scrollpane1;
VIEWS ON THIS POST

171

Posted on:

Wednesday 17th October 2012
View Replies!

if statement problem

I am new to Java Scripting and I am trying to write some code or if statement for the following. I have 2 JButtons (one labeled btnAddTwo and one lableled btnSubOne) and one text field.I am trying to get the btnAddTwo to add 2 when I click it and the btnSubOne to subtract one from the total in the text field. I built my program in netbean as a gui frame. Everthing works except for my counting.
VIEWS ON THIS POST

153

Posted on:

Wednesday 17th October 2012
View Replies!

Printing invicible JTable with Column removed - JTable.PrintMode.FIT_WIDTH problem

My JTable is a table with some columns including a checkbox column. When the user clicks on the print button, the program will create an invisible copy of the visible table, then add a rowsorter to exclude all the rows with a checkbox that is set to false. then remove the checkbox column from the table. For the table to print I manually change the size of the table (else the content will not print). That is how I set up the table, I hope it made sense. But it is when I set the table to print with JTable.PrintMode.FIT_WIDTH thats not working as it should. The table is not printed across the whole page, like it still believes that the removed column is still there, resulting in that the rigthmost column will be cut, and not all data will be printed. I don't have this problem when printing JTable.PrintMode.NORMAL. I hope my explanation made sense. I have tried a long time to fix this but without result. I'd be gratefull if someone could help me. Here is the code. edit: I have removed the code till someone who knows tells me it is okay (see the two posts below).
VIEWS ON THIS POST

158

Posted on:

Wednesday 17th October 2012
View Replies!

Tricky JTextArea problem

I have a JTextArea (or more than one) inside a JScrollPane The JScrollPane, has VERTICAL_SCROLLING_AS_NEEDED, no horizontal scrolling. When the frame is resized the scrollpane resizes accordingly. My problem is: Suppose I have 1000 words of text to put into the JTextArea. If I squash the frame horizontally, the words wrap around which is fine, and vertically, the scrollbar kicks in. But I just want to display 3 lines of text, and always finish with three dots ... when there is more text, but no room for it. I used setPreferredSize on the JTextArea which makes sure I get three lines worth. But when I select the text, the left over text is still hidden below the 3 lines. I don't want to display this text, just use 3 dots... Can anyone help
VIEWS ON THIS POST

163

Posted on:

Wednesday 17th October 2012
View Replies!

thread problem

In a swing application, when ok button is clicked, i want to new a class ScanCard (implements ScannerListener and PropertyChangeListener), and I want to wait till ScanCard is finished then doAction(), if like the code showed, the doAction() is performed before or during ScanCard runing, what should I do to achieve the purpose this.okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvt){ if (btnGroup.getSelection() == null) doSomething; else { dispose(); try { ScanCard scanCard = new ScanCard(); if (true) doAction(); }catch() {} } } });
VIEWS ON THIS POST

211

Posted on:

Wednesday 17th October 2012
View Replies!

problem drawOval() cant be found.

I am trying out this tutorial to get this drawOval() to work but the compiler tells me that the drawOval cant be found. I triple checked that my initialization is in place, and I have imported the proper library to get it to work. So I am at a loss here. my code: import java.awt.*; import java.awt.Graphics; import javax.swing.*; import javax.swing.event.*; public class Oval_Sub extends JFrame { private JSlider slider; private drawOval myPanel; public void Oval_Sub() { super("the title"); myPanel = new drawOval(); myPanel.setBackGroundColor(Color.ORANGE); // SwingConstants.HORIZONTAL sets the slider to move left to right or vise versa // 0, 200 sets the min and max value the slider has on the appropriate ends slider = new JSlider(SwingConstants.HORIZONTAL, 0, 200, 10); // sets the ticks or hash marks on the slider to determine intervals in values // the argument 10 refers to setting a tick every 10 pixels slider.setMajorTickSpacing(10); slider.setPaintTicks(true); slider.addChangeListener( new ChangeListener() { public void StateChanged(ChangeEvent e) { // setD() comes from Oval.java // get the value from slider and pass it to setD() myPanel.setD(slider.getValue()); } } // end ChangeListener() ); // end addChangeListener(); add(slider, BorderLayout.SOUTH); add(myPanel, BorderLayout.CENTER); } }
VIEWS ON THIS POST

189

Posted on:

Wednesday 17th October 2012
View Replies!

interface updating problem

Hi all, I am displaying image histograms on a user interface. Each histogram is represented by a class I wrote which extends JComponent. The painting is done the proper way through paintComponent and repaint() and it works great. In my GUI constructor, I display the histograms.. pane7.add(graphs[0]); pane7.add(graphs[1]); pane7.add(graphs[2]);
VIEWS ON THIS POST

166

Posted on:

Wednesday 17th October 2012
View Replies!

GUI Fluctuation problem in swing

I have a dialogue in which i am entering values. After submit I am checking for duplicate values in database and if exist I am again creating the same dialogue. As it can happen many times. I want to continue with that code. So I have used while loop and I am checking the flag value which I get after calling action_insertok() See the code while (!result) { result=true; DialogFactory.showDialog(null, "Add Assessment Type", assessDialogPage, new ACTION_InsertOk(), true, true); }
VIEWS ON THIS POST

216

Posted on:

Wednesday 17th October 2012
View Replies!

JTable and data binding problem [please close, found solution]

, I am using NetBeans 6.8 and got some problems when I want to add something to binded data. I have created a JTable (myListTable) that is binded with LinkedList (myList). I have created JButton (addRowButton) that should add new MyItem to myList which (probably) should add a row with that item to myListTable... and this is where the problem occurs. Firstly I have tried this:@Action public void addRow() { myList.add(new MyItem(myList.size(), "Random num: "+Math.random())); }
VIEWS ON THIS POST

146

Posted on:

Wednesday 17th October 2012
View Replies!