List of usage examples for java.awt TextField TextField
public TextField(int columns) throws HeadlessException
From source file:Main.java
public static void main(String[] args) { Frame f = new Frame("FlowLayout demo"); f.setLayout(new FlowLayout()); f.add(new Button("Red")); f.add(new Button("Blue")); f.add(new Button("White")); List list = new List(); for (int i = 0; i < args.length; i++) { list.add(args[i]);//from w w w .j av a 2 s .c om } f.add(list); f.add(new Checkbox("Pick me", true)); f.add(new Label("Enter name here:")); f.add(new TextField(20)); f.pack(); f.setVisible(true); }
From source file:ClipMe.java
ClipMe() { super("Clipping Example"); add(tf = new TextField("Welcome"), "North"); add(ta = new TextArea(), "Center"); ta.setEditable(false);//from ww w .j ava 2s .com Panel p = new Panel(); p.add(copy = new Button("Copy")); p.add(paste = new Button("Paste")); add(p, "South"); setSize(250, 250); }
From source file:abfab3d.param.editor.URIEditor.java
public URIEditor(Parameter param) { super(param); m_textField = new TextField(EDITOR_SIZE); Object val = m_param.getValue(); String sval = ""; if (val != null) { sval = val.toString(); }//from ww w . j a v a2s .c o m m_textField.setText(sval); m_textField.addActionListener(this); m_open = new JButton("Open"); m_open.setToolTipText("Open File"); panel = new JPanel(new FlowLayout()); panel.add(m_open); panel.add(m_textField); String user_dir = System.getProperty("user.dir"); Preferences prefs = Preferences.userNodeForPackage(URIEditor.class); String last_dir = prefs.get(LASTDIR_PROPERTY, null); String dir; if (last_dir != null) dir = last_dir; else dir = user_dir; fc = new JFileChooser(dir); m_open.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int returnVal = fc.showDialog(parent, "Open File"); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); String dir = file.getPath(); int idx = dir.lastIndexOf(File.separator); if (idx > 0) { dir = dir.substring(0, idx); Preferences prefs = Preferences.userNodeForPackage(URIEditor.class); prefs.put(LASTDIR_PROPERTY, dir); } m_param.setValue(file.getAbsolutePath()); informParamChangedListeners(); } } }); }
From source file:TreeLinkTest.java
public void init() { tl = new TreeLayout(); setLayout(tl);//from ww w . j av a 2 s . c o m Button root = new Button("This is the root"); add("Root", root); tl.setRoot(root); Component x = new Label("A random label"); add("label", x); tl.setParent(x, root); Component y; y = new TextField("Add any component"); add("comp", y); tl.setParent(y, root); x = new List(); ((List) x).add("List entry"); ((List) x).add("Similarly useless list entry"); add("list", x); tl.setParent(x, root); x = new Button("Extremely long and unnecessary button title"); add("button", x); tl.setParent(x, y); x = new MyCanvas(getImage(getDocumentBase(), "icons/tools.gif")); add("image", x); tl.setParent(x, y); }
From source file:GUIManagerQuery.java
/*************************************************************************** * Construct the GUIManagerQuery object, constructing the various components * and laying them out on the screen.//from w w w. j ava2 s. co m **************************************************************************/ public GUIManagerQuery() { super("GUIManagerQuery"); setLayout(new BorderLayout()); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); versionLabel = new Label("JMF v" + Manager.getVersion()); add(versionLabel, "North"); Panel lower = new Panel(); lower.add(new Label("Content/Protocol")); contentsField = new TextField(32); lower.add(contentsField); add(lower, "South"); results = new TextArea(20, 80); results.setEditable(false); add(results, "Center"); Panel controls = new Panel(); controls.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); hintsButton = new Button("Hints"); gbc.gridx = 0; gbc.gridy = 0; controls.add(hintsButton, gbc); hintsButton.addActionListener(this); playersButton = new Button("Players"); gbc.gridy = 1; controls.add(playersButton, gbc); playersButton.addActionListener(this); processorsButton = new Button("Processors"); gbc.gridy = 2; controls.add(processorsButton, gbc); processorsButton.addActionListener(this); sourcesButton = new Button("DataSources"); gbc.gridy = 3; controls.add(sourcesButton, gbc); sourcesButton.addActionListener(this); add(controls, "East"); }
From source file:GUIMediaStatistics.java
/********************************************************************** * Construct the GUIMediaStatistics object, constructing the various * components and laying them out on the screen. **********************************************************************/ public GUIMediaStatistics() { super("GUIMediaStatistics"); setLayout(new BorderLayout()); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from w w w. j a v a2 s . co m } }); Panel filePanel = new Panel(); filePanel.add(new Label("File:")); mediaField = new TextField(40); filePanel.add(mediaField); browseButton = new Button("browse..."); filePanel.add(browseButton); browseButton.addActionListener(this); getStatsButton = new Button("get stats..."); filePanel.add(getStatsButton); getStatsButton.addActionListener(this); add(filePanel, "North"); results = new TextArea(80, 10); results.setEditable(false); add(results, "Center"); }
From source file:jotp.java
public void init() { setBackground(Color.white);/* w ww . j ava2s. co m*/ setLayout(new GridLayout(6, 1)); Panel panel1 = new Panel(); add(panel1); Font titlefont = new Font("TimesRoman", Font.BOLD, 14); panel1.setFont(titlefont); panel1.add(new Label(String.valueOf(version) + ": The Java OTP (aka S/Key) calculator!")); Panel panel2 = new Panel(); panel2.setLayout(new FlowLayout()); add(panel2); panel2.add(new Label("Challenge (e.g. \"55 latour1\"):")); chaltf = new TextField(24); panel2.add(chaltf); Panel panel3 = new Panel(); panel3.setLayout(new FlowLayout()); add(panel3); panel3.add(new Label("Secret Password:")); pwtf = new TextField(24); pwtf.setEchoCharacter('*'); panel3.add(pwtf); Panel panel4 = new Panel(); panel4.setLayout(new FlowLayout()); add(panel4); panel4.add(new Button(String.valueOf(md4label))); panel4.add(new Button(String.valueOf(md5label))); Panel panel6 = new Panel(); panel6.setLayout(new FlowLayout()); add(panel6); panel6.add(new Label("One-Time Password:", Label.LEFT)); otptf = new TextField(40); panel6.add(otptf); Panel panel7 = new Panel(); add(panel7); panel7.add(new Label("jotp by Harry Mantakos, " + "http://www.cs.umd.edu/~harry/jotp")); }
From source file:vincent.DynamicDataDemo.java
/** * Constructs a new demonstration application. * /*from ww w .java2 s. c om*/ * @param title the frame title. */ public DynamicDataDemo(final String title) { super(title); this.series = new TimeSeries("Random Data"); final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); setContentPane(content); // Zone de saisie de commande vers le port srie : TextField zoneSaisie = new TextField(10); chartPanel.add(zoneSaisie); zoneSaisie.setLocation(100, 300); zoneSaisie.validate(); zoneSaisie.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_ENTER) { TextField textField = (TextField) e.getComponent(); try { BufferedWriter writer = tempSerialReader.getEcrivainPortSerie(); writer.write(textField.getText()); writer.write('\r'); writer.flush(); } catch (IOException l_ex) { LOG.error("erreur d'criture sur le port srie: ", l_ex); } } } }); temperatureCouranteLabel = new Label("XX.XC"); chartPanel.add(temperatureCouranteLabel); chartPanel.add(tempsDeChauffeEtRelicat); chartPanel.add(paramsPid); tempSerialReader = new TempSerialReader(this); }
From source file:SocketApplet.java
/** Initialize the GUI nicely. */ public void init() { Label aLabel;/*from ww w. j a v a 2s.com*/ setLayout(new GridBagLayout()); int LOGO_COL = 1; int LABEL_COL = 2; int TEXT_COL = 3; int BUTTON_COL = 1; GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 100.0; gbc.weighty = 100.0; gbc.gridx = LABEL_COL; gbc.gridy = 0; gbc.anchor = GridBagConstraints.EAST; add(aLabel = new Label("Name:", Label.CENTER), gbc); gbc.anchor = GridBagConstraints.CENTER; gbc.gridx = TEXT_COL; gbc.gridy = 0; add(nameTF = new TextField(10), gbc); gbc.gridx = LABEL_COL; gbc.gridy = 1; gbc.anchor = GridBagConstraints.EAST; add(aLabel = new Label("Password:", Label.CENTER), gbc); gbc.anchor = GridBagConstraints.CENTER; gbc.gridx = TEXT_COL; gbc.gridy = 1; add(passTF = new TextField(10), gbc); passTF.setEchoChar('*'); gbc.gridx = LABEL_COL; gbc.gridy = 2; gbc.anchor = GridBagConstraints.EAST; add(aLabel = new Label("Domain:", Label.CENTER), gbc); gbc.anchor = GridBagConstraints.CENTER; gbc.gridx = TEXT_COL; gbc.gridy = 2; add(domainTF = new TextField(10), gbc); sendButton = new Button("Send data"); gbc.gridx = BUTTON_COL; gbc.gridy = 3; gbc.gridwidth = 3; add(sendButton, gbc); whence = getCodeBase(); // Now the action begins... sendButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String name = nameTF.getText(); if (name.length() == 0) { showStatus("Name required"); return; } String domain = domainTF.getText(); if (domain.length() == 0) { showStatus("Domain required"); return; } showStatus("Connecting to host " + whence.getHost() + " as " + nameTF.getText()); try { Socket s = new Socket(getCodeBase().getHost(), 3333); PrintWriter pf = new PrintWriter(s.getOutputStream(), true); // send login name pf.println(nameTF.getText()); // passwd pf.println(passTF.getText()); // and domain pf.println(domainTF.getText()); BufferedReader is = new BufferedReader(new InputStreamReader(s.getInputStream())); String response = is.readLine(); showStatus(response); } catch (IOException e) { showStatus("ERROR: " + e.getMessage()); } } }); }
From source file:PlayerOfMedia.java
/*************************************************************************** * Construct a PlayerOfMedia. The Frame will have the title supplied by the * user. All initial actions on the PlayerOfMedia object are initiated * through its menu (or shotcut key)./*from w ww. j a v a2s . c om*/ **************************************************************************/ PlayerOfMedia(String name) { super(name); /////////////////////////////////////////////////////////// // Setup the menu system: a "File" menu with Open and Quit. /////////////////////////////////////////////////////////// bar = new MenuBar(); fileMenu = new Menu("File"); MenuItem openMI = new MenuItem("Open...", new MenuShortcut(KeyEvent.VK_O)); openMI.setActionCommand("OPEN"); openMI.addActionListener(this); fileMenu.add(openMI); MenuItem quitMI = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q)); quitMI.addActionListener(this); quitMI.setActionCommand("QUIT"); fileMenu.add(quitMI); bar.add(fileMenu); setMenuBar(bar); /////////////////////////////////////////////////////// // Layout the frame, its position on screen, and ensure // window closes are dealt with properly, including // relinquishing the resources of any Player. /////////////////////////////////////////////////////// setLayout(new BorderLayout()); setLocation(100, 100); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if (player != null) { player.stop(); player.close(); } System.exit(0); } }); ///////////////////////////////////////////////////// // Build the Dialog box by which the user can select // the media to play. ///////////////////////////////////////////////////// selectionDialog = new Dialog(this, "Media Selection"); Panel pan = new Panel(); pan.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); mediaName = new TextField(40); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 2; pan.add(mediaName, gbc); choose = new Button("Choose File..."); gbc.ipadx = 10; gbc.ipady = 10; gbc.gridx = 2; gbc.gridwidth = 1; pan.add(choose, gbc); choose.addActionListener(this); open = new Button("Open"); gbc.gridy = 1; gbc.gridx = 1; pan.add(open, gbc); open.addActionListener(this); cancel = new Button("Cancel"); gbc.gridx = 2; pan.add(cancel, gbc); cancel.addActionListener(this); selectionDialog.add(pan); selectionDialog.pack(); selectionDialog.setLocation(200, 200); //////////////////////////////////////////////////// // Build the error Dialog box by which the user can // be informed of any errors or problems. //////////////////////////////////////////////////// errorDialog = new Dialog(this, "Error", true); errorLabel = new Label(""); errorDialog.add(errorLabel, "North"); ok = new Button("OK"); ok.addActionListener(this); errorDialog.add(ok, "South"); errorDialog.pack(); errorDialog.setLocation(150, 300); Manager.setHint(Manager.PLUGIN_PLAYER, new Boolean(true)); }