Hello good day. I am having trouble letting my listeners wait on each other. I have a 1. JComboBox 2. JList - groups 3. JList - students The choice from the JComboBox, clears and updates the groups JList by way of an actionlistener. The ListSelectionListener for the groups JList, then responds to you selecting data (that was just added). The choice is refelcted in the students JList. The trouble is I am getting a NullPointerException at random times. I believe this happens because in order to update the groups-JList via the ComboBox's ActionListener, I need to clear it's contents first. …

Member Avatar
Member Avatar
+0 forum 6

Is there any way that I don't use lots of IF statements?,right now it is according to Index of combo box items. else if(e.getSource().equals(jcb1)) { int selectedindex = jcb1.getSelectedIndex(); String comb_string = (String)jcb1.getSelectedItem(); if(selectedindex==1) { try { //String sql_command ="select * , count(*) over (partition by 1) total_rows from Employer where Employername = ? "; String sql_command ="select * from Employer where Employername = ? "; PreparedStatement st=con.prepareStatement(sql_command); st.setString(1,comb_string); Result = st.executeQuery(); int test =0; String Store=""; String Response =""; test++; if(Result.next()) { String add1=Result.getString(3); first.setText(add1); String add2=Result.getString(28); second.setText(add2); String add3=Result.getString(4); third.setText(add3); String add4=Result.getString(6); fourth.setText(add4); if(test !=0) { /*Result.absolute(test); DisplayData();*/ …

Member Avatar
Member Avatar
+0 forum 1

Hi guys, I'm having trouble with my code and I'm kind of new in Java so I don't know what to do. I have to do a program with Buttons and each button has to take me to another class (I don't know if I'm being clear). For example if I click the button "Bingo" my class named Bingo (which I already have) should run but I don't know how to do that. Here's my code: import java.awt.*; import javax.swing.*; import java.io.*; import java.awt.event.*; public class GameFrame extends JFrame implements ActionListener { private static final long serialVersionUID = 1L; JFrame …

Member Avatar
Member Avatar
+0 forum 4

Hello, I'm in a pickle. (Please observe the code) In the actionPerformed method, I don't know how I can get the value of the variable 'minutes'. I can get 'hours' by e.getActionCommand(), but can't do minutes that way. I need to get both 'hours' and 'minutes' at the same action. Please help. import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.JLabel; public class OuterClass extends JFrame{ private JLabel hours; private JLabel minutes; public OuterClass(){ hours = new JLabel("Hours?"); minutes = new JLabel("Minutes?"); add(hours); add(minutes); InnerClass actionHandler = new InnerClass(); hours.addActionListener(actionHandler); minutes.addActionListener(actionHandler); } private class InnerClass implements ActionListener{ …

Member Avatar
Member Avatar
+0 forum 2

import java.awt.*; 02 import javax.swing.*; 03 import java.util.Random; 04 import java.awt.event.*; 05 import java.awt.Color; 06 import java.awt.Graphics; 07 public class actualstuff extends JFrame 08 { 09 private JTextField textField1; 10 public static int index=0; 11 public static Graphics gx; 12 public actualstuff() 13 { 14 Container container=getContentPane(); 15 container.setLayout(new FlowLayout()); 16 textField1=new JTextField(15); 17 container.add(textField1); 18 setSize(325, 100); 19 setVisible(true); 20 TextFieldHandler handler=new TextFieldHandler(); 21 textField1.addActionListener(handler); 22 } 23 public static void main(String args[]) 24 { 25 actualstuff application=new actualstuff(); 26 application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 27 } 28 private class TextFieldHandler implements ActionListener 29 { 30 public void actionPerformed(ActionEvent event) 31 { 32 …

Member Avatar
Member Avatar
+0 forum 2

I created a JTree and also created a class which implements `TreeSelectionListener` then I pass that object into the JTree's function `addTreeSelectionListener`. In the [JavaDocs](http://docs.oracle.com/javase/tutorial/uiswing/examples/components/TreeDemoProject/src/components/TreeDemo.java), there is an example where they implemented the function `public void valueChanged(TreeSelectionEvent e)` within the main class and passed `this` into `addTreeSelectionListener`. I tried to implement this into my class, but it didn't work. package tutorials; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTree; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeSelectionModel; public class TreeDemo extends JFrame{ private JTree tree; public TreeDemo() { super("Tree Demo"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setPreferredSize(new Dimension(500, 300)); DefaultMutableTreeNode structure = new DefaultMutableTreeNode("Main Tree"); …

Member Avatar
Member Avatar
+0 forum 3

Hello, I need assistance with this java program I am writing, Im trying to make two buttons and when you click the button, it has a counter, and everytime you click it it prints a message saying I was clicked n times. This is what I have so far and I am pretty stuck. For example, I dont know how to assign a button a counter. [CODE] import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; public class ButtonViewer { private static final int FRAME_WIDTH = 400; private static final int FRAME_HEIGHT = 360; int counter1 = 0; int counter2 = 0; public …

Member Avatar
Member Avatar
+0 forum 6

I'm noob at GUI Swing. I have 2 questions. 1)I'm trying to implement a program that reads a text file, so I can use it to add multiple tabs to the program based on the amount of data in the text file. For example, text file have 3 names. I will use the 3 names to make 3 tabs labeling their name in each of them. Where do I call this fileIO, readContacts() part? When I put readContacts() in the Constructor AddTabs(), the program cannot display the frame. When I take readContacts() out of the Contructor, the the program can …

Member Avatar
Member Avatar
+0 forum 12

Hi everyone, I have a javascript, jQuery, and c++ background so im not completely new but am just starting to learn Java in a University setting. In our first program we are to run it within a Do...While loop so the user can click a JButton for yes or no, if they wish to run it again. It's a simple Prime Factorization program. I missed a day this week and think I missed the instruction I am missing for this loop to work. From what I have been reading for the last few hours is that I need to have …

Member Avatar
Member Avatar
+0 forum 10

Hi folks! I'm trying to wire simple code and so far I'm stuck on ActionListener. My program should contain (JMenu) Menu called SELECT and two options InnerFrame 1 and InnerFrame 2. To debug it I've started using System.EXIT , unfortunately I cant compile my program, I'm receiving an error: "java:48: non-static method addActionListener(java.awt.event.ActionListener) cannot be referenced from a static context JMenuItem.addActionListener(this);" code goes here [code] import javax.swing.JInternalFrame; import javax.swing.JDesktopPane; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JMenuBar; import javax.swing.JFrame; import javax.swing.KeyStroke; import java.awt.event.*; import java.awt.*; /* * InternalFrameDemo.java * */ public class InternalFrameDemo1 extends JFrame implements ActionListener{ public InternalFrameDemo1() { super("My First …

Member Avatar
+0 forum 0

Hi All, I was having trouble with getting my program to display all the necessary conversions. Here is a snippet of the code to help explain what I want to do: [CODE] private class CalcListener implements ActionListener{ public void actionPerformed(ActionEvent e){ String centInput, inchInput, meterInput, yardInput; double cent, inch, meter, yard; yardInput = yardsText.getText(); inch = Double.parseDouble(yardInput) * 36.00; cent = Double.parseDouble(yardInput)* 91.44; meter = Double.parseDouble(yardInput) * 0.9144; inchText.setText(String.valueOf(inch)); centText.setText(String.valueOf(cent)); meterText.setText(String.valueOf(meter)); [/CODE] This will allow me to put an input into the "Yards" Textfield so that when I click calculate, the inch, cent, and meter Textfields will display their proper …

Member Avatar
Member Avatar
+0 forum 36

am try to create notepad in java... menu item actionlisteners are not working...except exit... what is the problem with my code??? and is there any sequence follow... because am try to use jScrollpane the text area will be blocked??? code is.. [CODE]import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JSeparator; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JScrollBar; import java.awt.Container; //import javax.swing.JFlowLayout; import javax.swing.JScrollPane; class Notepad extends JFrame implements ActionListener{ JMenu file; JMenu edit ; JMenu format ; JMenu view; JMenu help; JMenuBar jb; JMenuItem New ; JMenuItem open; JMenuItem save; JMenuItem save1; JMenuItem ps ; JMenuItem print ; …

Member Avatar
Member Avatar
+0 forum 6

Okay, So this code I have is giving me an error: non-static variable this cannot be referenced from a static context. Here is the code: [code=java] package macey; /** * @author WolfShield */ import java.awt.*; import java.awt.event.*; import javax.swing.*; public class DemoConv implements ActionListener { private JLabel answerL; public static void Conv() { // Content JPanel content = new JPanel(); content.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); // Actual Content JTextField userInputNum, userInputUnit, userOutputUnit; JButton convCalculateB; JLabel leftBarL, rightBarL, multSymbolL, left1L, right1L, equalsL, answNumL, answUnitL; // Variable Labels JLabel rightBottomConvUnitL, rightTopConvNumL; //Assign all above content leftBarL = new JLabel("__________"); c.gridy=2; …

Member Avatar
Member Avatar
+0 forum 5

Hi all, I am new to java swing programming.I want to develop an application which has a panel with an array of grid points(not grid cells). The number of columns and rows of the grid points must be user specific. Once such an environment is created, the user's mouse click on the diff grid points must be captured and those points alone must be highlighted in a different color. As of now, i've only created the Jpanel. I know it is possible to get the coordinates of the mouse click use mouse events, but i do not know how to …

Member Avatar
+0 forum 0

[CODE] private JButton[] buttons; private static final Character firstChar = 'A'; private static final Character lastChar = 'D'; /** Creates a new instance of ButtonPanel */ public ButtonPanel() { buttons = new JButton[4]; setLayout(new GridLayout(2,2)); Character label = firstChar; for (JButton b: buttons) { b = new JButton("" + label); buttons[label - firstChar]= b; b.setActionCommand("" + label); // for use in ButtonWatcher label++; add(b); //is this how to create and add a ButtonWatcher for each of the buttons b.addActionListener(new ButtonWatcher()); } [/CODE] Ive tried this code with a buttonWatcher implements ActionListener class but it wont work and im wondering have …

Member Avatar
Member Avatar
+0 forum 1

Hi, This is my first forum post and I'm very new to both the daniweb and programming community. I've been working on a project for a month or so and it involves clicking JButton to change the values of the text associated with the JButton clicked. Everything runs fine except one button expands to cover the entire screen when I click a button. What am I doing wrong? Code's right here [CODE]// The Driver class import java.awt.Graphics; import java.awt.Image; import java.awt.MediaTracker; import java.awt.Toolkit; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JFrame; import javax.swing.JPanel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JOptionPane; import …

Member Avatar
Member Avatar
+0 forum 1

I am having a hard time figuring out how to use the db object created in the first action event within the second action... how can i make the object visible there? i am trying to say add a record to db object by saying something like ... class Action2 implements ActionListener { public void actionPerformed (ActionEvent e) { String record1 = field2.getText(); String record2 = field3.getText(); String record3 = field4.getText(); db.addRecord(record1, record2, record3); // but cannot see instance of db here } } [CODE]import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyDbGUIPanel extends JPanel { private JTextField field1, field2,field3,field4; …

Member Avatar
Member Avatar
+0 forum 3

Helooo, Attached is a pic of my main screen of my program. Basicly it's a phone book app similiar to one you'd have on your phone. The thing that I can't wrap my mind around, is that you see the nice big textArea there? After you've added a contact now. What can I use that the user can just click on the name of the contact in the textArea and the appropriate window will display for the contact? As far as I know, you cant add an actionListener on a piece of text in a textArea. So what do I …

Member Avatar
Member Avatar
+0 forum 5

Hi there, I just wanted to find out if one can have a actionListener() in one .class file and then have the actionEvent() in another .class file? If not, how would I go about to get the same effect? Thanks!

Member Avatar
Member Avatar
+0 forum 7

So my coding is a temperature converter. I have gotten everything down the way that it is wanted by the assignment except for one part. When I run the program, put in a value and select the radio button for conversion, no output ever shows up. Was hoping that someone could take a look and see what is going on with it. Here is the coding, it is two separate classes within java. [CODE]import javax.swing.*; /** * This program allows the user to convert temperatures * */ public class ConvertTemp { public static void main(String[] args) { JFrame frame = …

Member Avatar
Member Avatar
+0 forum 1

Hi guys, I'd really appreciate it if someone could look over my code and tell me why my JComboBox isn't working. I've got 3 Classes, 2 for the GUI, one for the standalone which the array is contained in. [CODE]import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.JComponent; import javax.swing.SwingUtilities; import javax.swing.UIManager; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.KeyEvent; public class BHSSDatabase { public static void main (String[] args) { //Create and set up the window. JFrame frame = new JFrame("The BHSS Database"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); //Add content to the window. frame.add(new BHSSDatabasePanel(), BorderLayout.CENTER); //Display the window. frame.pack(); frame.setVisible(true); } }[/CODE] …

Member Avatar
Member Avatar
+0 forum 1

public class OpenMenuListener implements ActionListener { public void actionPerformed(ActionEvent ev) { if(ev.getSource() == a) { f2 = new JFrame("shashikant verma"); p2 = new JPanel(); f2.getContentPane().add(p2); String str = "<html>"+"<h>"+"<P ALIGN = \"CENTER\">"+"<i>"+"<font size = \"10\">"+"<font color= \"#800080\">"+"CORRECT DEFINITION AND<br>"+"STRUCTURE OF FUNCTION y = f(x) "+"<br>"+"</i>"+"</h>"+"<P ALIGN = \"LEFT\">"+"<font size = \"6\">"+"<u>"+"Introduction <br>"+"</u>"+"<P ALIGN=\"LEFT\">"+ "<font size = \"4\">"+ "It is a well-known fact that the Logicians,Mathematicians and Physicists have been pointing out about deficiencies in the definition<br>"+ "and structure of a function.This will lead us to the conclusion that in many physical phenomena there are failure processes <br>" + "of Physics …

Member Avatar
Member Avatar
+0 forum 4

The End.