Home Answers Viewqa Java-Beginners java GUI program

 
 


lancau
java GUI program
1 Answer(s)      4 years and 9 months ago
Posted in : Java Beginners

View Answers

August 25, 2008 at 4:25 PM


Hi friend,

import javax.swing.*;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;


public class TextExampleDemo extends JPanel implements ActionListener {
protected JTextField textField;
protected JTextArea textArea;

private final static String newline = "\n";

public TextExampleDemo() {
super(new GridBagLayout());

textField = new JTextField(20);
textField.addActionListener(this);

textArea = new JTextArea(5, 20);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

//Add Components to this panel.
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.HORIZONTAL;
add(textField, c);

c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
add(scrollPane, c);
}

public void actionPerformed(ActionEvent evt) {
String text = textField.getText();
textArea.append(text + newline);
textField.selectAll();
textArea.setCaretPosition(textArea.getDocument().getLength());
}

private static void createAndShowGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);

//Create and set up the window.
JFrame frame = new JFrame("Text display in textarea example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
JComponent newContentPane = new TextExampleDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
frame.setSize(300,300);
frame.setVisible(true);
}

public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
----------------------------------

Read for more information,

http://www.roseindia.net/java/

Thanks.

Amardeep









Related Pages:
java GUI program - Java Beginners
java GUI program  java program that creates the following GUI, when user enter data in the textfield, the input will be displayed in the textarea...://www.roseindia.net/java/ Thanks. Amardeep
Java GUI Program - Java Beginners
Java GUI Program  How is the following program supposed to be coded... by Day 7 under a thread in your Team Forum called Week Three Program for 10 points...://www.roseindia.net/java/ Thanks. Amardeep
Writing a GUI program - Java Beginners
Writing a GUI program  Hello everyone! I'm trying to write a program... if that number is prime or not. When the second button is pressed the program... to write the code for the GUI. Could anyone please help?  Hi Friend
GUI
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
Java gui program for drawing rectangle and circle
Java gui program for drawing rectangle and circle   how to write java gui program for drawing rectangle and circle? there shoud be circle.... and the program must also show message dialog "this is a red circle" when click
GUI convert to celsius program - Java Beginners
GUI convert to celsius program  how to write java GUI program... information on Swing Examples visit to : http://www.roseindia.net/java/example/java/swing/ Thanks
Java GUI to build a Student Registration Program
Java GUI to build a Student Registration Program   Write a program... in sorted order by last name. Demonstrate the correct operation of your program by creating a driver program to load the student data base and the course data
java gui-with jscroll pane
java gui-with jscroll pane  Dear friends.. I have a doubt in my gui... the window manually.....but i need this through my program...How can i show that text feilds through my program.... some one please help me.... Thanks in advance
java gui-with jscroll pane
java gui-with jscroll pane  Dear friends.. I have a doubt in my gui... the window manually.....but i need this through my program...How can i show that text feilds through my program.... some one please help me.... Thanks in advance
GUI problem - Java Beginners
GUI problem  how to write java program that use JTextField to input data and JTextField to display the output when user click Display Button??  Handle the actionPerformed event for JButton and try doing something like
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
Java GUI code
Java GUI code  Write a GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows: Amount deposited: 80000.00 Years: 15 Interest rate: 7.75 Total Amount: Hint** to solve this problem
Java: Basic GUI
Java NotesBasic GUI Next - Big Blob This first example just shows what... program 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // structure/CalcV1.java // Fred Swartz - December 2004 // GUI
GUI Interface - Java Beginners
GUI Interface  Respected sir, please send me the codimg of basic... and multiplication. But use classes javax swing java awt java awt.event no other... calculator program."); class CalcGUI extends JFrame { private final Font BIGGER
GUI Alternatives
, it isn't difficult to build a Graphical User Interface (GUI) in Java, but it is hard... to use the Java GUI libraries to build your GUI. There are alternatives... your interface be in Java? You can use existing GUI technologies like Flash
GUI Tips
Java NotesGUI Tips [Beginning of list of GUI tips -- needs much more] Program structure main can be in any class, but it's often simplest.... Events and communication After the GUI is constructed, the program stops execution
Java scroll pane-java GUI
Java scroll pane-java GUI  Dear friends.. Very Good morning. I have a doubt in my gui application. Take ex:- My gui application has 1 Jscrollpane... my program.... Thanks dears in advance
Rationale for GUI tutorial decisions
Table of Contents Rationale for GUI tutorial decisions Java offers many... that some Java textbooks are written without any GUI coverage, and others cover... of programs that have no GUI interface. For example, Java is very popular
Programming - Transform Name - GUI 0
Java: Programming - Transform Name - GUI 0 Write a GUI program to redisplay a name, possibly transformed. This Java program will reformat a user's name... be good extra credit for this program. You can easily use the Java functions
GUI application program
GUI application program  Write a GUI application program that meets the following requirements: Create an array with 100 randomly chosen integers. Create a textfield to enter an array index and another textfield to display
Fill-in: Rainfall GUI
Java NotesFill-in: Rainfall GUI Name ______________________________ (5... like someplace on this page. (15 points) Fill in the blanks in this program... 79 80 81 82 83 84 // RainfallGUI2.java - Provides a GUI interface
Java GUI code- creating a circle
Java GUI code- creating a circle  My assignment is to write a program... is (x,y)(x2,y2). The program should then output the circle's radius, circumference...; //GUI components JLabel lClx, lCly, lCircumrx, lCircumry, lRadius
Summary - Basic GUI Elements
Java: Summary - Basic GUI Elements In this tutorial we will learn about Basic GUI elements in Java program. Following table summarizes the variable... JFrame.EXIT_ON_CLOSE to terminate program when close box clicked. w.setResizable
java gui
java gui   friends... good day.. i have doubt in java gui. ? i created 1 java gui application. That has two text fields jtext1,jtext2. case: user entered value in first textfield(jtext1) and pressed the enter key . the cursor
Rainfall GUI Questions
Java NotesRainfall GUI Questions Name ______________________________ This is part of the code to implement the GUI that was used with the Rainfall program. The problem is that there is no button to calculate the average. Add
Java GUI problem with linklists and administration - Java Beginners
Java GUI problem with linklists and administration  Hi, I'm having trouble making a GUI interface in java, where a list of names are displayed using a jList. The java program should be able to allow the user to add names, remove
Java GUI
Java GUI  1) Using Java GUI, create a rectangular box that changes color each time a user click a change color button. 2) Modify Question 1 to include a new button named insert image, that allow user to insert a bitmap image
Java GUI
Java GUI  difference between swing and applet
How can I write a GUI stack program by Java to push Image files instead of other data type items?
How can I write a GUI stack program by Java to push Image files instead of other data type items?   How can I write a GUI stack program by Java to push Image files instead of other data type items? for the push instruction I
GUI problem
GUI problem  Create a class called CDProgram and write a GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows: Amount deposited: 80000.00 Years: 15 Interest Rate: 7.75 Hint
Serializing GUI Components Across Network - tutorial
Serializing GUI Components Across Network 2001-03-14 The Java Specialists' Newsletter [Issue 013a] - Serializing GUI Components Across Network Author... to as many people as you know who might be interested in Java. Serializing GUI
Java GUI - Java Beginners
Java GUI  HOW TO ADD ICONS IN JAVA GUI PROGRAMMES
Convert the code to GUI
Java GUI Class Example  Java GUI Class Example
Convert the code to GUI
GUI Java JSP application  GUI Java JSP application
Convert the code to GUI
Java and GUI application Example  Java and GUI application Example
java program
java program  Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets... the monthly and total payments. (using GUI input) use (import javax.swing.JOptionPane
GUI-Model Rainfall program
Java NotesGUI-Model Rainfall program   This is an example.... A complete, running, GUI program is built automatically, and it's only... statistics. Show an example of separating the GUI from the model
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
Java GUI - Java3D
Java GUI  1) Using Java GUI, create a rectangular box that changes color each time a user click a change color button. 2) Modify Question 1 to include a new button named insert image, that allow user to insert a bitmap image
Netbeans GUI Ribbon
Netbeans GUI Ribbon  how to create ribbon task in java GUI using netbeans
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
GUI Structural Patterns
Java NotesGUI Structural Patterns Structuring the program - Separating the Model In all ways of structuring a GUI program, there is one vitally important... quickly as a program grows. This is not an advantage only
Java Gui - Java Beginners
Java Gui  HOW TO ADD LINK LABELS IN JAVA PROGRAMMES
Java GUI - Java Beginners
Java GUI  How to use JTray in java programme?  Hi friend, JTrayIcon jtc= new JTrayIcon(image); // jPopupMenu is a javax.swing.JPopupMenu jtc.setRightClickTarget(jPopupMenu); jtc.show(); Thanks
Gui Interface - Java Beginners
Gui Interface  hi I have two seperate interfaces in the same projects . my question is how can I access this interface using a jbutton (i.e jbutton = next where next points to another interface addCourse.java) What would
java program - Java Beginners
java program   1.java program to Develop a multi-threaded GUI application of your choice. 2.program to Develop a template for linked-list class along with its methods in Java
GUI 2 - Java Beginners
GUI 2  How can I modify this code? Please give me a GUI...;GUI Example");pack();show();}public void actionPerformed(ActionEvent event... world and like it alot. I was wondering where can I go to learn more about java
GUI - Java Beginners
GUI testing  GUI testing in software testing  HiNow, use the code and get the answer.import javax.swing.*;public class DemoTryCatchDialog...;GUI Example");pack();show();}public void actionPerformed(ActionEvent event
java gui - Java Beginners
java gui  i have to create dynamically databse,table, and number of field..inside that field dynamically data can be entered with type of variable..after entering all the dat in different form field label,i should have a button
Regarding GUI Applications
Regarding GUI Applications  How to create a save and open jmenu item in java desktop application

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.