Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training  
 

Lost Using Swing Components

Ads

 
 

Share on Google+Share on Google+

Andrew Meikle
Lost Using Swing Components
1 Answer(s)      6 years and 7 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!");
}

}

Ads
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


Ads









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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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