The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:




Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Software Testing >> .Net Testing

Pages: 1
Adebiade
Newbie


Reged: 06/27/12
Posts: 4
I'm A student i need help on my project J++
      #710928 - 06/27/12 02:12 PM

I hook down on my project on java, i was trying to make a Button event that will save datas Through Jcomponent like JTextField, JComboBox, JTestArea from my GUI interface to a FILE, to make one of my JTexField Autogenerated,

Please check my Codes they are running fine but the mistake i don't know
===========================================================

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.*;

/**
*
* @author Panacea
*/
public class Trial extends javax.swing.JFrame implements ActionListener {

/**
* @param args the command line arguments
*/
static String summary;
@SuppressWarnings("PackageVisibleField")
static String Name, Password;
private JFrame f = new JFrame("Employee Login");
private JTextField Name1 = new JTextField(10);
@SuppressWarnings("PackageVisibleField")
//JButton button = new JButton("Save Ticket");
private JPasswordField Password1 = new JPasswordField(15);
private JButton add = new JButton("Save Login");
private JButton open = new JButton("Open Ticket Window");

public Trial(){
{
//JFrame

f.setLayout(new BorderLayout());

JPanel p = new JPanel();
p.setLayout(new FlowLayout());
p.add(new JLabel("Login Id"));
p.add(Name1);
p.add(new JLabel("Password"));
p.add(Password1);
f.add(p, BorderLayout.WEST);

// Panel for button

JPanel P1 = new JPanel();
P1.setLayout(new FlowLayout());
P1.add(add);
P1.add(open);
add.addActionListener(this);
open.addActionListener(this);

f.add(P1, BorderLayout.SOUTH);

//JFrame properties

f.setVisible(true);
f.setSize(550, 200);
}
}




//public class Listener implements ActionListener {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent e) {
if (e.getSource() == add) {
Name = (" ");
Password = (" ");

Name = Name1.getText().trim();
Password = Password1.getText().trim();
summary = ("\t\t\t\tCUSTOMER ID:\t\n\n\n\n" + Name+"\n") + (" PASSWORD: " + Password);

String Data = Trial.summary ;
try {
BufferedWriter reader = new BufferedWriter(new FileWriter(new File("C:/Users/Panacea/Desktop/tutorial/java_Project_Unit_6/AddInfo.txt"), true));
reader.write(Data);
reader.newLine();
reader.close();

System.out.println("Done!!!!!!");
} catch (IOException d) {
System.out.println("Error is " + d);
}
}
}


public static void main(String[] args) {
// TODO code application logic here
new Trial();
new Trial2();
}

@SuppressWarnings("serial")
public class Trial2 extends JFrame implements ActionListener {

JTextArea TA4 = new JTextArea(5, 10);
JTextField TF3 = new JTextField(10);
JTextField TF7 = new JTextField(10);
JTextField TF2 = new JTextField(10);
JTextArea TA1 = new JTextArea(5,20);
JTextArea TA = new JTextArea(5,30);
JTextField TF1 = new JTextField(10);
JComboBox cb = new JComboBox();
JButton button = new JButton("Save Ticket");
String TextField1, TextField2, TextField3, TextField4, TextArea1,TextArea2,TextArea3,ComboBox1;
final static String BUTTONPANEL = "High";
final static String TEXTPANEL = "Low";
final static String BUTTONPANEL1 = "Medium";
static String result;


public Trial2()
{
JFrame frame2 = new JFrame("Ticket Field");
frame2.setVisible(true);
frame2.setSize(800, 600);

JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints c2 = new GridBagConstraints();
frame2.getContentPane().add(panel);
frame2.add(panel);
//
// panel.setBackground(Color.GREEN);


c2.insets = new Insets(10, 10, 10, 10);
JPanel panel1 = new JPanel();
panel1.setBackground(Color.GREEN);
panel1.setLayout(new GridBagLayout());
//frame2.add(panel1, BorderLayout.NORTH);
frame2.getContentPane().add(panel1, BorderLayout.NORTH);
JLabel label = new JLabel("Create New Ticket");
c2.gridx = 0;
c2.gridy = 1;
panel1.add(label,c2);

JLabel label2 = new JLabel("Ticket ID");
c2.gridx = 0;
c2.gridy = 2;
panel1.add(label2, c2);


c2.gridx = 1;
c2.gridy = 2;
panel1.add(TF1, c2);

GridBagConstraints c3 = new GridBagConstraints();

frame2.add(panel);



c3.insets = new Insets(10, 10, 10, 10);
JPanel panel2 = new JPanel();
panel2.setBackground(Color.GREEN);
panel2.setLayout(new GridBagLayout());
frame2.getContentPane().add(panel2, BorderLayout.CENTER);


c3.insets = new Insets(10, 10, 10, 10);
JPanel panel5 = new JPanel();
panel5.setBackground(Color.GREEN);
panel5.setLayout(new GridBagLayout());
frame2.getContentPane().add(panel5, BorderLayout.SOUTH);
JLabel label6 = new JLabel("Product Details");
c3.gridx = 0;
c3.gridy = 1;
panel5.add(label6, c3);


c3.gridx = 1;
c3.gridy = 1;
panel5.add(TA,c3);


panel5.setBackground(Color.GREEN);
panel5.setLayout(new GridBagLayout());
frame2.getContentPane().add(panel5, BorderLayout.SOUTH);

JLabel label7 = new JLabel("Customer Complaints");
c3.gridx = 0;
c3.gridy = 2;
panel5.add(label7, c3);

c3.gridx = 1;
c3.gridy = 2;
panel5.add(TA1,c3);

JLabel label8 = new JLabel("Urgency");
c3.gridx = 0;
c3.gridy = 3;
panel5.add(label8, c3);

String comboBoxItems[] = {BUTTONPANEL, BUTTONPANEL1, TEXTPANEL };
JComboBox cb = new JComboBox(comboBoxItems);
c3.gridx = 1;
c3.gridy = 3;
panel5.add(cb, c3);
//
// JPanel P9 = new JPanel();
// P9.setLayout(new FlowLayout());
// P9.add(button);
// P9.setBackground(Color.GREEN);
// frame2.add(P9, BorderLayout.SOUTH);
// button.addActionListener(this);
c3.gridx = 0;
c3.gridy = 4;
panel5.add(button,c3);
button.addActionListener(this);

JPanel panel0 = new JPanel();
panel0.setLayout(new GridBagLayout());
GridBagConstraints c4 = new GridBagConstraints();
c4.insets = new Insets(10, 10, 10, 10);
frame2.getContentPane().add(panel0, BorderLayout.WEST);


panel0.setBackground(Color.GREEN);


JLabel label0 = new JLabel("Customer Name");
c4.gridx = 0;
c4.gridy = 1;
panel0.add(label0,c4);

c4.gridx = 1;
c4.gridy = 1;
panel0.add(TF2, c4);

JLabel labelc = new JLabel("Customer Phone");
c4.gridx = 0;
c4.gridy = 2;
panel0.add(labelc,c4);


c4.gridx = 1;
c4.gridy = 2;
panel0.add(TF7, c4);

GridBagConstraints c1 = new GridBagConstraints();

c1.insets = new Insets(10, 10, 10, 10);
JPanel panelA = new JPanel();
panelA.setBackground(Color.GREEN);
panelA.setLayout(new GridBagLayout());
frame2.getContentPane().add(panelA, BorderLayout.EAST);
JLabel label4 = new JLabel("Customer Email");
c1.gridx = 0;
c1.gridy = 1;
panelA.add(label4, c1);


c1.gridx = 1;
c1.gridy = 1;
panelA.add(TF3, c1);

JLabel label5 = new JLabel("Customer Address");
c1.gridx = 0;
c1.gridy = 2;
panelA.add(label5, c1);

c1.gridx = 1;
c1.gridy = 2;
panelA.add(TA4, c1);

//=====================================================
//GridBagConstraints c5 = new GridBagConstraints()

c4.insets = new Insets(10, 10, 10, 10);
JPanel paneld = new JPanel();
paneld.setBackground(Color.GREEN);
paneld.setLayout(new GridBagLayout());
frame2.getContentPane().add(paneld, BorderLayout.CENTER);
}

//public class Listener implements ActionListener {


public void actionPerformed(ActionEvent e) {

if(e.getSource() == button){
TextField1= ("");
TextField2 = ("");
TextField3 = ("");
TextField4 = ("");
TextArea1 = ("");
TextArea2 = ("");
TextArea3 = ("");
ComboBox1 = ("");


TextField1 =TF1.getText().trim();
TextField2 =TF2.getText().trim();
TextField3 = TF3.getText().trim();
TextField4 = TF7.getText().trim();
TextArea1 = TA.getText().trim();
TextArea2 = TA1.getText().trim();
TextArea3 = TA4.getText().trim();
ComboBox1 = cb.getSelectedItem().toString().trim();
result= ( TextField1 )+( TextField2)+(TextField3)+(TextField4)+(TextArea1)+(TextArea2)+(TextArea3);
String Data1 = Trial2.result;
try {
BufferedWriter reader = new BufferedWriter(new FileWriter(new File("C:/Users/Panacea/Desktop/LoginSystem/Project5/project.txt"), true));
reader.write(Data1);
reader.newLine();
reader.close();

System.out.println("Done!!!!!!");
} catch (IOException d) {
System.out.println("Error is " + d);
}
}
}


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 0 anonymous users are browsing this forum.

Moderator:  AJ 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 1442

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5