import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JComboBox; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; public class OtakuHigh extends JFrame{ private JLabel label, label1, label2, label3, label4, label5, label6, label7, label8; private JTextField text1, text2, text4, text5, text7, text8; private JComboBox Mbox, Dbox, Sbox, Ybox, SCbox; private JButton Qbutton; String[] Month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; String[] Day = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}; String[] …

Member Avatar
Member Avatar
+0 forum 2

I want to have a changing output in the 2nd textfield that is 'output' in my Action class as I enter input in the 'input'textfield. I don't know why it doesn't give any output... pls help The comboBoxes convertTo---contains "IEEE" and "DEC" while precisions contain "Long", "Single", "Double". Any advice or tips will be appreciated! :)) import javax.swing.*; import javax.swing.text.*; import java.awt.event.*; import java.awt.*; import javax.swing.event.*; public class Action implements DocumentListener, ItemListener{ public JTextField output; public JTextField input; public JComboBox convertTo, precisions; public String toForm, prec, in; public char preci; public void insertUpdate(DocumentEvent de) { getIn(); } public void removeUpdate(DocumentEvent …

Member Avatar
Member Avatar
+0 forum 5

Hey Fellas, I created 10 JTextFields using and ArrayLists: `ArrayList<JTextField> textFArray = new ArrayList<>();` textFArray.add(new JTextField()); gbc.gridx = 1; for (int i = 0; i < 10; i++) { gbc.gridy++; add(textFArray.get(i), gbc); textFArray.add(new JTextField(i)); } What I need to do: I need to get the values of what ever the user puts into the JTextField(s) and total the inputs and assign them to a variable. This is what I have so far: double totalTemp; for(JTextField temps: textFArray){ //System.out.println(temps.getText()); totalTemp = Integer.parseInt(temps.getText()); } I know the code snippet above doesnt work properly. If you uncomment the the one line, it can …

Member Avatar
Member Avatar
+0 forum 1

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Burger extends JFrame implements ActionListener { JLabel lblForAll, lblBelow, pic, pic1, pic2, pic3, pic4, pic5, pic6, pic7; JRadioButton rBtn, rBtn1, rBtn2, rBtn3; JCheckBox cBtn, cBtn1, cBtn2, cBtn3; JTextField txt, txt1, txt2, txt3, txt4, txt5; JButton btn1, btn2; ButtonGroup btnG; int ham=25, egg=15, bacon=40, chicken=36, coleslow=8, cheese=10, cucumber=12, tomatoe=14; //ImageIcon ham1 = new ImageIcon("1.png"), egg1 = new ImageIcon("2.png"), bacon1 = new ImageIcon("3.png"), chicken1 = new ImageIcon("4.png"); Burger() { super("Burger Ordering System"); setLayout(null); add(lblForAll = new JLabel("Select Burger: ")); lblForAll.setBounds(10,20,100,20); add(lblForAll = new JLabel("Add Ons: ")); lblForAll.setBounds(150,20,100,20); add(rBtn = new JRadioButton("Ham Burger")); rBtn.setBounds(10,40,100,20); add(rBtn1 …

Member Avatar
Member Avatar
+0 forum 6

I have a program that creates a GUI with three text fields in it, and two of these fields is supposed to accept a numeric value. I want to know how to get the numeric entries and store them in a variable for further calculations please. I know how to get the string value entered into the one field, you just need to code, **String varname = txt1.getText();** and I was hopig for something similar for number values, a double to be specific, as there does not seem to be any **.getDouble();** available?? If someone could advise me on this, …

Member Avatar
Member Avatar
+0 forum 1

I am unable to execute the editProfile() method in MainMenu class. The purpose of the method is to be able to extract the bean values and display them on the empty textfield. I am not sure if i did it correctly. any recommendations for any changes to editProfile() method. public class MainMenu extends javax.swing.JFrame { Academic ac = new Academic(); academicBean bn = new academicBean(); /** * Creates new form MainMenu */ public MainMenu() { initComponents(); // myProfile(); // editProfile(); } public void myProfile() { ac.retrieveAcademic(); nameLabel.setText(""+ac.title+" "+ac.forename+" "+ac.surname); roleLabel.setText("Role: " + ac.role); roomLabel.setText("Room: " + ac.room); pageLabel.setText("Page: " + …

Member Avatar
Member Avatar
+0 forum 8

Hey everyone, I am attempting to add an array of JTextFields to one of my JPanels and for some reason i keep getting errors and the program crashes when i run it. I know i am prob making some noob mistake but this a project for my first Java class so please do not look down on me lol A picture of the INTENDED end result is here if u want to see it ![ManyNumbersStart](/attachments/large/3/ManyNumbersStart.png "ManyNumbersStart") Any help would be greatly appreciated. Thank you! import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ManyNumbers { public static void main(String [] args) …

Member Avatar
Member Avatar
+0 forum 6

I have a textfield, and that only accept integer numbers. If user input charter type value it shows JOptionpane Error Message and when user click on the ok button in optionpane message the textfield clear itself public void nosgetit(DocumentEvent documentEvent){ DocumentEvent.EventType type = documentEvent.getType(); if(type.equals(DocumentEvent.EventType.CHANGE)){ } if(type.equals(DocumentEvent.EventType.INSERT)){ String ns=nos_txt.getText(); char [] c=ns.toCharArray(); for(int i=0; i < ns.length(); i++){ if ( !Character.isDigit(c[i])){ JOptionPane.showMessageDialog(null, "You must input number", "ERROR", JOptionPane.ERROR_MESSAGE); } } } if(type.equals(DocumentEvent.EventType.REMOVE)){ } }

Member Avatar
Member Avatar
+0 forum 1

I was trying to reduce my jtextfield height, since it is for user to enter first name. somehow when i run the code, the box is just too big, is there anyway to change the textfield height? i tried with setPrefferedSize but somehow it showing error, mayb i put it wrongly in a wrong place Totally a beginner here.... here is my code import java.util.*; import javax.swing.*; import javax.swing.JList; import javax.swing.ButtonGroup; import java.awt.*; import java.awt.BorderLayout; public class RegistrationSystem extends JPanel{ JLabel lblfirstname = new JLabel("First Name:"); JLabel lbllastname = new JLabel("Last Name:"); JLabel lblage = new JLabel("Age:"); JLabel lblgender = …

Member Avatar
Member Avatar
+0 forum 1

I have a class that has a text area. the code is as follows package view; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.ScrollPaneConstants; public class LabelStatus extends JPanel { /** * */ private static final long serialVersionUID = 1L; JFrame frame; public static JTextArea test; JLabel title; public LabelStatus() { JLabel title = new JLabel ("INCOMING MESSAGES ",JLabel.CENTER); title.setFont(new Font ("Serif", Font.BOLD,30)); this.add(title); GridBagConstraints k = new GridBagConstraints(); k.gridx = 10; k.gridy = 10; test = new JTextArea(60,60); test.setLineWrap(true); test.setWrapStyleWord(true); test.setEditable(false); JScrollPane spane = new JScrollPane(test); spane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); GridBagLayout gbl …

Member Avatar
Member Avatar
+0 forum 4

have various classes representing various types of program-genres (comedy, drama etc). I have a text file filled with '-' seperated values that get read by a class called Processing and puts them into a LinkedList. I have another class GUI_g that creates the GUI. It has 3 JTables. One for the list and 1 for each Channel. (Channel 1 and Channel 2). The JTable listTable gets filled from the linkedlist and whenever a user clicks on a row, the textfields' text changes accordingly. I tried with 3 fields (Title, Genre and Duration) and it worked, with the 3 textfields showing …

Member Avatar
Member Avatar
+0 forum 1

Pls can anyone help me with a code that will help me get values in a main class from another class... I have two classes, one is user class that has the main method and the other which is process class. I am having a jtextfield and a jbutton in the user's class, I want a method in the process class that can change the value of the jtextfield in the user class when the jbutton is clicked, it will call the the method in the process class that will do that...

Member Avatar
Member Avatar
+0 forum 14

I have two class. One class is for JAVA text area another class has a object. I want to print in the textarea from another class. The class with the text area. public class LabelStatus extends JPanel { /** * */ private static final long serialVersionUID = 1L; final static JTextArea test =new JTextArea(40, 60); public LabelStatus() { JLabel title = new JLabel ("INCOMING MESSAGES ",JLabel.CENTER); title.setFont(new Font ("Serif", Font.BOLD,30)); this.add(title); GridBagConstraints k = new GridBagConstraints(); k.gridx = 10; k.gridy = 10; test.setLineWrap(true); test.setWrapStyleWord(true); test.setEditable(false); JScrollPane spane = new JScrollPane(test); spane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); GridBagLayout gbl = new GridBagLayout(); gbl.setConstraints(spane,k); JPanel panel = …

Member Avatar
Member Avatar
+0 forum 3

I have been searching high and low to find something remotely close to what I am trying to accomplish and have failed, miserably. I have read Oracle and tutorials, but have a hard time comprehending everything related to java. It is all so confusing. I would just be grateful for some advice in the correct direction because I want to cry and give up. I am trying to create a program (with a GUI) that has several jtextfields. Across from them are a permanent string of shopping list items for reference. I am trying to get what the user inputs …

Member Avatar
Member Avatar
+0 forum 2

I would like to move the mouse cursor from one position to another within a Jtextfield after a condition is satisfied. I do not know what to use. Thank you

Member Avatar
Member Avatar
+0 forum 4

I was given a client and server and I have to create a gui for it. I have done the entering part using the JTextField and the problem is getting the output of the class to go to JTextArea. (Its a Client server simple chat program) Here is the set up I currently have the client is a class and the GUI is another class. The GUI creates the class base on the user input ( read from the JTextField) and I am suppose to return the consol message like the userinput message , connected and etc.... from the consol …

Member Avatar
Member Avatar
+0 forum 1

I am writing a program, but I cannot find what is wrong with the code. Only need to show one MP3, or an error message if there are any missing fields or an incorrect entry for seconds. It is not storing information about previous songs; it just display the current MP3. Here are the problem entire descriptions. [B]Create a class MP3 with instance variables for: artist, song, album, track length (in seconds)[/B]. Provide a constructor, get/set methods, and a toString. method. The toString method should convert the track length into minutes and seconds. For example, 265 seconds would be displayed …

Member Avatar
Member Avatar
+0 forum 5

Hey so I've been working on a lab for my intro to software developing class and have been trying to get my program to work for several days now. It's a real basic program, im sure someone will be able to figure out the issue im having. Hopefully once I learn what I'm doing I'll be able to return the favor, but until then thanks, heres the code. Right now there are no errors indicated by Eclipse, is it only a syntax error then, i feel like im missing something. [CODE] package lab8; import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import …

Member Avatar
Member Avatar
+0 forum 5

I have a problem with getting an input from class A to class B. I already created a method which gets the value but when I call it in class b it returns empty. These are my codes: [B]CLASS A[/B] [CODE] public class log extends javax.swing.JFrame { public String name; private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { System.out.println("1"+getuser()); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/devweb", "root", "123456"); PreparedStatement statement = con.prepareStatement("select User,pwd from account"); ResultSet rs = statement.executeQuery(); name = user.getText(); String pwd = jTextField2.getText(); while (rs.next()) { if (rs.getString("User").equals(name) && rs.getString("pwd").equals(pwd)) { user.getText(); result now = new result(); getuser(); now.res(); now.jTextField1.setText(name); …

Member Avatar
Member Avatar
+0 forum 2

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

I'm having problems with my code regarding the value of the string I get with the JTextfield.getText() method my code goes this way: [CODE](keypressedevent evt){ int id=evt.getId(); char c = evt.getKeyChar; String s = JTextField.getText()+c; System.out.print(s); } [/CODE] if the textfield contains for example: apple and you type s, it will print apples. but if you pressed backspace, it would still print apples it wouldn't update until you press another key. Is there a way to get the desired output here? Thanks in advance!

Member Avatar
Member Avatar
+0 forum 4

Hi, I am working on a project which requires to update a JEditorPane or JTextField simultaneously by multiple clients. It is something like this. [B][1]. There are several users( i.e a group) with the same application which contains a JEditorPane. [2]. There is a group leader for a group( note: there is an option to be a group leader in the same application) and each an every other user( i.e group member) will be connected to the group leader via individual sockets. [3]. After connecting as a group every one can type anything into the JEditorPane and that content should …

Member Avatar
Member Avatar
+0 forum 4

i need to access the current text of a JTextField from another method but i get an error here is the code [CODE]public Calc(){ JTextField textBox1, textBox2; setLayout(new FlowLayout()); textBox1 = new JTextField(" Time "); textBox2 = new JTextField(" Exp "); JLabel lRate = new JLabel("Rate"); JButton calc = new JButton("Calculate"); textBox1.setSize(100, 10); textBox2.setSize(100, 10); calc.setToolTipText("Click to Calculate"); calc.setActionCommand("disable"); calc.setMnemonic(KeyEvent.VK_D); calc.addActionListener(this); add(textBox1); add(textBox2); add(calc); add(lRate); } public void actionPerformed(ActionEvent e) { if ("disable".equals(e.getActionCommand())) { String rate = calcu(textBox1.getText(), textBox2.getText()); lRate.setText(rate); try{ write(rate); } catch(IOException e1){System.err.println(e1);} } }[/CODE]

Member Avatar
Member Avatar
+0 forum 9

How do I allow the display to show numbers with the commas, but then when it does the calculations, have the commas go away for the math since obviously java can't read commas in calculations? example [CODE] DecimalFormat df0 = new DecimalFormat("###,###.00"); JFormattedTextField loanText = new JFormattedTextField(df0);[/CODE] the user puts a number in say 500000, and when the user goes to the next TextField, it automatically sets the loanTextField to 500,000 since I told it to. When the program takes those TextFields and grabs the number 500,000 - it reverts the number back to 500000 so it can read it? …

Member Avatar
Member Avatar
+0 forum 1

I am wanting to reference an object of type JTextField and convert it to JFormattedTextField. Is it possible to convert to a subclass? I tried coding something to the affect of [CODE]ClassA.object = new JFormattedTextField(); ClassA.object.setValue(new Integer(number)); [/CODE] But no success. Any suggestions?

Member Avatar
Member Avatar
+0 forum 3

Okay, First and foremost im new to the forum. Hi and Thx to anyone who helps :D Anyhow, i would like to ask you guys if it is possible to separate a String with tokens one by one. Then make them appear in the jTextField with only 1 word per field. Lets say in Customer.txt i got the following test asdf asdf then i would like em to appear(3 separate textfields): TextField: test Textfield: asdf textfield: asdf [CODE] BufferedReader reader; try{ reader = new BufferedReader(new FileReader("Customer.txt")); String strLine = reader.readLine(); StringTokenizer st = new StringTokenizer(strLine); jTextField1.read(reader, st); reader.close(); } catch(FileNotFoundException …

Member Avatar
Member Avatar
+0 forum 4

Hi Guys, I posted earlier, and I figured it out after a few hours of playing around with it. Now, a new question arises. Is it possible to get the input from a JTextField and add it into a JComboBox via an array? The only thing stopping me from achieving this I think, is how to put the user input from the JTextField into an array. All I'd have to do after that is access that array though the JComboBox which I do understand. There's no use for ActionListener here, right? Only for JButtons? Thanks in advance!

Member Avatar
Member Avatar
+0 forum 2

Hello all, I'm trying to add a multiple JTextFields onto a single JPanel that has been already initialized thanks to the Design tool from the JFrame. I'm pretty sure that I already added them and I'm not getting any errors but they aren't showing up when I execute the program. my code is: initComponents(); for (int i = 0; i < MemoryCell.length; i ++){ MemoryCell[i] = new javax.swing.JTextField(); MemoryCellLocation.add(MemoryCell[i]); } //MemoryCellLocation is the JPanel and MemoryCell is the JTextFields

Member Avatar
Member Avatar
+0 forum 12

The End.