Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Lost Using Swing Components

Have Programming Question? Ask it here!
 
 
 


Andrew Meikle
Lost Using Swing Components
1 Answer(s)      3 years and 8 months ago
Posted in : Java Beginners


Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the "To", "Subject", and "Message:" text. The "To" and "Subject:" text areas should provide a single line for data entry. The "Message:" area should allow multiple lines of input and be able to scroll if necessary to accommodate a long message. The user clicks a button to send the email message. When the message is complete and the a send button is clicked, the application displays "Mail has been sent!" on a new line in the message area. I then save the files as JEmauil.java. This is what the code is that I have and it shows what I am missing. I would be indebted if someone could help me:

//Insert missing code here. import java.awt.*; import java.awt.event.*;

public class JEMail extends JFrame implements ActionListener { //Insert missing code here. private JTextField toField = new JTextField(24); private JLabel subjectLabel = new JLabel("Subject:"); private JTextField subjectField = new JTextField(24); //Insert missing code here. private JButton sendButton = new JButton("Send"); private JTextArea message = new JTextArea(4, 22);

public JEMail()
{
    super("WebBuy Company E-Mail");
    setSize(370, 270);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = getContentPane();
    FlowLayout flow = new FlowLayout(FlowLayout.RIGHT);
    pane.setLayout(flow);
//Insert missing code here.
    panel1.add(toLabel);
//Insert missing code here.
    pane.add(panel1);
    JPanel panel2 = new JPanel();
    panel2.add(subjectLabel);
    panel2.add(subjectField);
//Insert missing code here.
    JPanel panel3 = new JPanel();
    panel3.add(messageLabel);
    message.setLineWrap(true);
    message.setWrapStyleWord(true);
    JScrollPane scroll = new JScrollPane(message,
       JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
       JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    panel3.add(scroll);
//Insert missing code here.
    JPanel panel4 = new JPanel();
    panel4.add(sendButton);
    pane.add(panel4);
    sendButton.addActionListener(this);
//Insert missing code here.
}

public static void main(String[] arguments)
{
    JEMail email = new JEMail();
//Insert missing code here.
}
public void actionPerformed(ActionEvent event)
{
  Object source = event.getSource();
  if (source == sendButton)
    message.append("\nMail has been sent!");
}

}


Advertisement
View Answers

December 13, 2010 at 1:12 PM


Hi Friend,

Try the following code:

import java.awt.*; 
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class JEMail extends JFrame implements ActionListener { 
    private JTextField toField = new JTextField(24);
    private JLabel subjectLabel = new JLabel("Subject:"); 
    private JTextField subjectField = new JTextField(24); 
    private JLabel toLabel = new JLabel("To:"); 
 private JButton sendButton = new JButton("Send"); 
 private JLabel messageLabel = new JLabel("Message:"); 
 private JTextArea message = new JTextArea(4, 22);
 StringBuffer buffer=new StringBuffer();
public JEMail()
{
    super("WebBuy Company E-Mail");
    setSize(370, 270);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   setLayout(null);
    toLabel.setBounds(10,10,100,20);
    toField.setBounds(150,10,100,20);
    subjectLabel.setBounds(10,40,100,20);
    subjectField.setBounds(150,40,100,20);

    messageLabel.setBounds(10,70,100,20);
    message.setBounds(150,70,300,80);

    sendButton.setBounds(150,170,80,20);
    message.setLineWrap(true);
    message.setWrapStyleWord(true);
   add(toLabel);
    add(toField);
     add(subjectLabel);
      add(subjectField);
       add(messageLabel);
        add(message);
         add(sendButton);
sendButton.addActionListener(this);
    setVisible(true);
    setSize(500,300);
}

public static void main(String[] arguments)
{
    JEMail email = new JEMail();
}
public void actionPerformed(ActionEvent event){
    Object source = event.getSource();
  if (source == sendButton){
      String mess=message.getText();
   message.append(mess+"\nMail has been sent!");
   System.out.println("Mail has been sent");
   }
}
}

Thanks



Related Tutorials/Questions & Answers:
Lost Using Swing Components
Lost Using Swing Components  Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy... be indebted if someone would help me out as I am lost: //Insert missing code here
Lost Using Swing Components
Lost Using Swing Components  Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy Company that allows a user to compose the three parts of a complete email message
Advertisements
Lost Using Swing Components
Lost Using Swing Components  Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy Company that allows a user to compose the three parts of a complete email message
Lost Using Swing Components(2)
Lost Using Swing Components(2)  Here is the code block corrected: //Insert missing code here. import java.awt.*; import java.awt.event.*; public class JEMail extends JFrame implements ActionListener { //Insert missing code
Lost Using Swing Components(3)
Lost Using Swing Components(3)  Hello, I sound like every other newbie but I desperately need help. I have to write an application for the WebBuy Company that allows a user to compose the three parts of a complete email message
JFrame Components Printing - Swing AWT
JFrame Components Printing  hi sir i am doing a project so i am working in netbeans i have to print a JFrame it contains Labels and few... link: http://www.roseindia.net/java/example/java/swing/Print.shtml Hope
JFrame components printing - Swing AWT
Swing Components"); WindowShow.setNativeLookAndFeel(); Container content...JFrame components printing  hi sir thanks a lot for your reply.../example/java/swing/Print.shtml and downloaded the codes and compiled it got
JFrame components printing - Swing AWT
Swing Components"); WindowShow.setNativeLookAndFeel(); Container content...JFrame components printing  hi sir thanks a lot for your reply.../example/java/swing/Print.shtml and downloaded the codes and compiled it got
JFrame Components Printing - Swing AWT
PrintExample() { super("Printing Swing Components...JFrame Components Printing  hi sir thanks a lot for your reply.../example/java/swing/Print.shtml and downloaded the codes and compiled it got
Introduction to Components
you will learn to use Swing components. Some advantages of using... Java NotesIntroduction to Components Swing Components You can draw... for you to put on the screen. These are called components. An example
Display Logo on login form using swing
Display Logo on login form using swing In this tutorial, you will learn how to display a logo in login form using swing components. Here is an example where... file from the system and using setIcon() method, the image as a logo will get
swing components are not running in my system what to do now??
swing components are not running in my system what to do now??  Exception in thread "main" java.lang.ExceptionInInitializerError at javax.swing.JOptionPane.showInputDialog(Unknown Source
Editing UI components using managed bean
Editing UI components using managed bean  Hello friends... I want to edit the properties of a inputText on JSP page using its managed bean. I have a simple inoutText and commandButton on jsp page and on click of button, i want
Finding Lost Frames - Java tutorial
Finding Lost Frames 2001-05-10 The Java Specialists' Newsletter [Issue 019] - Finding Lost Frames Author: Dr. Heinz M. Kabutz If you are reading... Lost Frames Something that I have encountered in some almost-complete
creation of table using a Java swing
creation of table using a Java swing  how to create a table dynamically in Java swing
Reading .doc file using swing
Reading .doc file using swing  Sir, Could U Please Tell me the Way To Read .doc file in java using swing,with code
Using swing - Java Beginners
Using swing  How can one use inheritance and polymophism while developing GUI of this question. Develop an application that allows a student to open an account. The account may be a savings account or a current account
Components
Components in Flex4 is the simple extension of the components of Flex3. In this section, you will learns different types of spark components to be used in Flex4. Here is the list of spark components
how to give validation using javascript in swing
how to give validation using javascript in swing   how to give validation using javascript in swing....... can somebody give code for username and password validation using javscript and swing
automatically resend when connection lost in sending email
automatically resend when connection lost in sending email  send automatically email when connection lost in sending bulk email using javamail for exp more than 10000 emails
automatically resend when connection lost in sending email
automatically resend when connection lost in sending email  send automatically email when connection lost in sending bulk email using javamail for exp more than 10000 emails
automatically resend when connection lost in sending email
automatically resend when connection lost in sending email  send automatically email when connection lost in sending bulk email using javamail for exp more than 10000 emails
Creating Custom Components using JSF
JSF contains its basic set of UI components and provides an easy way of creating custom components of your own according to the need of the application. Components in JSF are elements like text box, button, table etc. that are used
how to set image in button using swing? - Swing AWT
how to set image in button using swing?  how to set the image in button using swing?  Hi friend, import java.awt.*; import...);}}); } } For more information on Swing visit to : http
how to create a header in jtable using java swing
how to create a header in jtable using java swing  how to create a header in jtable using java swing   d
Insert into table using Java Swing
INSERTION IN TABLE USING SWING In this section, We will insert rows into "Mysql" database using "Swing". What is Swing? Swing is the extension to the Awt library, includes new and improved components
GPS Lost Mobile Phone Tracking Services
. For using our GPS based lost mobile tracking service, you must have a GPS...GPS Lost Mobile Phone Tracking Services Now a day?s mobile phones are not only.... Our subscription charges are very low while our GPS Lost Mobile Tracking
java total lost data in hard drive
java total lost data in hard drive  please help me, i need java source code about total lost data in hard drive. how to find the total deleted data ih hard drive using java programming... this my project...pls help me
java total lost data in hard drive
java total lost data in hard drive  please help me, i need java source code about total lost data in hard drive. how to find the total deleted data ih hard drive using java programming... this my project...pls help me
JAVA TOTAL LOST DATA IN HARD DRIVE
JAVA TOTAL LOST DATA IN HARD DRIVE  please help me, i need java source code about total lost data in hard drive. how to find the total deleted data ih hard drive using java programming... this my project...pls help me
java total lost data in hard drive
java total lost data in hard drive  please help me, i need java source code about total lost data in hard drive. how to find the total deleted data ih hard drive using java programming... this my project...pls help me
How to Hide Button using Java Swing
Programming application how to hide the buttons using Java Swing. Please Visit this below reference link http://www.roseindia.net/tutorial/java/swing...How to Hide Button using Java Swing  Hi, I just begin to learn java
Components
Java NotesComponents Components (also known as "widgets") are the basic..., ... Components are placed in a container (eg, JPanel). The visual arrangement of the components depends on the container's layout. When the user does
Import object in Excel using java swing
Import object in Excel using java swing  Hi sir, I want to make a swing application where I can import a object by clicking a button. I am using...;browse (this browse path I want to give inside the swing code) Tick 'display as icon
Which one is better for creating a GUI using swings either Manual coding or IDE(NetBeans,eclipse)..? drag and dropping components
Which one is better for creating a GUI using swings either Manual coding or IDE... in java application developing.... Which one is better for creating a GUI using swings either Manual coding or IDE(NetBeans,eclipse)..? drag and dropping components
Sum of a Number using Swing
Sum of a Number using Swing       In this section, you will learn how to sum of a number using swing... of creating a frame is,  using single argument constructor of the JFrame class
Navigate Data using Java Swing
Navigate Data using Java Swing In this java tutorial section, you will learn how to navigate the Database data using Java Swing. For this, we have created a form with four buttons to perform an action. Through these buttons, we have
compareing images using java - Swing AWT
compareing images using java  hi can u please give me the code in java to compare imges..i have the program to get the pixel values using pixel... with another image,i.e,program to compare two images using the pixel values.. thank
Create Layout Components in a Grid in Java
layout components with the help of grid in Java Swing. The grid layout provides the facility to arrange some created GUI components for the frame. The grid... Create Layout Components in a Grid in Java   
Linking excel file with a application tool using swing
Linking excel file with a application tool using swing  I have to link an excel file with my application software using java swing.As soon as i click on the link button a window should open for selecting the excel file(just like
insert data into mysql databse using swing
insert data into mysql databse using swing   Blockquote hi, here is my code, i want code for store data into mysql database when click on submit button from access data from this form, please provide code, import java.awt.
SWING
SWING  A JAVA CODE OF MOVING TRAIN IN SWING
What is Java Swing?
and GUIs components. All Java Swing classes imports form the import.... JComponent In java swing, All components are used the JComponent except.... JFrame It extends the Frame and supports the swing components
swing
swing  How to make swing component auto-resizable when JFrame resize
swing
swing  Write a java swing program to delete a selected record from a table
How to create Multiple Frames using Java Swing
Multiple Frames in Java Swing In this section, you will learn how to create multiple frames. Java Swing provides the utility to show frame within another frame by providing the class JInternalFrame. With the use of this class, you can
Flex custom components
Custom Flex Components: In the Flex 3 development, User can create custom components using mxml or ActionScript. In this example user can see mxml custom component. The purpose to create custom components in the Flex application
create, edit ,open simple documents using java - Swing AWT
create, edit ,open simple documents using java   In my program I have a text area.How to create document which will contain text in text... want to use Java Swing or JSP? Do you want to create word document file
Java Swing
. Swing also supports a pluggable look and feel. Classes representing components... Java Swing       Swing... interface (GUI) components for Java programs. Swings are lightweight and 100
Swing
Swing  Write a java swing program to search the details of the students. Searching is performed on studentā??s first name. The details of all those students having same name as in given in searching criterion will be displayed
 

 

 

DMCA.com