Results 1 to 2 of 2
Thread: Displaying a JTextField?
- 10-22-2012, 11:07 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 3
- Rep Power
- 0
Displaying a JTextField?
I am trying to make the JTextField turn its input to a string that i can use in other classes and display it in System.out.println();
code:
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Level1Expeirement1 extends JFrame {
private static String title = "Expeirement1";
private static int width = 700;
private static int height = 700;
//buttons
private JPanel window = new JPanel();
private JButton cancel, ok, expirement3;
private Rectangle rcancel, rok, rexpirement3, ritem1;
private String hypothisis;
private JTextField item1 = new JTextField(hypothisis);
public static Font font = new Font("Comic Sans MS", Font.BOLD, 12);
public void Level1Expeirement1() {
setVisible(true);
setSize(width, height);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(window);
setLocationRelativeTo(null);
setTitle(title);
setBackground(Color.GREEN);
window.setLayout(null);
Drawbutton();
}
private void Drawbutton() {
//draws buttons
//level 1 button
ok = new JButton("ok");
// location size
// 20 50 80 100
rok = new Rectangle(60, 50, 180, 40);
ok.setBounds(rok);
window.add(ok);
//use to add graphics
//singleplayer.setIcon(new ImageIcon("res/singleplayer.png"));
cancel = new JButton("cancel");
// location size
// 20 50 80 100
rcancel = new Rectangle(60, 100, 180, 40);
cancel.setBounds(rcancel);
window.add(cancel);
item1 = new JTextField();
// location size
// 20 50 80 100
ritem1 = new Rectangle(60, 150, 180, 40);
item1.setBounds(ritem1);
window.add(item1);
//listener
item1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.out.println(hypothisis);
}
});
}
}
- 10-23-2012, 03:57 PM #2
Re: Displaying a JTextField?
Guide For New Members
BB Code List - Java Programming Forum
Go through the tutorial linked from the API of JTextField.
Thread moved from New to Java.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
Press enter on JTextField to make focus on next JTextField?
By userno69 in forum AWT / SwingReplies: 3Last Post: 11-14-2011, 05:13 AM -
displaying a formatted output on a jTextField
By techbossmb in forum AWT / SwingReplies: 1Last Post: 09-24-2009, 04:56 PM -
Displaying text in a JTextArea when a JtextField is Selected
By Frys82 in forum AWT / SwingReplies: 8Last Post: 08-13-2009, 04:23 AM -
how to access jTextField of one JFrame1 from JFrame2 & Modify JTextField contents
By sumit1mca in forum AWT / SwingReplies: 1Last Post: 01-30-2009, 06:44 PM -
Displaying text in a JTextField after pressing a button
By RLRExtra in forum New To JavaReplies: 5Last Post: 01-17-2008, 09:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks