快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

小金体育充值网址_酒文化网进入



这个代码读写的是Txt文件,不必要任何数据库支持。共两个java文件,一个示例txt文件。

JavacourseworkPart2.java

/*==========================================================================================

*Designed and implemented by Henry Tshobo, student @ The University of Greenwich*

==========================================================================================*/

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class JavacourseworkPart2 extends JFrame { // Super class

private JLabel lbname, lbsurname, lbaddress, lbpostcode, lbphone, lburl, lbdate, jLabel, jLabel2;

private JTextField txtname, txtsurname, txtaddress, txtpostcode, txtphone, txturl, txtdate;

private JButton displayall, submit, clear, exit;

private JCheckBox football, basket, boxing, hockey, rugby, judo, karate, gym, swiming, westling;

private JRadioButton optMale, optFemale;

private JTextArea output, display;

private JPanel panel, panel2, panel3, panel4, panel5;

private ButtonGro小金体育充值网址up radioGroup;

private String sex, sport, nm, 小金体育充值网址sn, add, pc, ph, ur, dt, disp;

ActionEventHandler handler = new ActionEventHandler();

RadioButtonHandler rhandler = new RadioButtonHandler();

public JavacourseworkPart2() { //Contructor

super( "Sport Membership Designed and Implemented by Henry Tshobo" );

initComponents(); //Call Method initComponents

}

private void initComponents() {//Method to initialize all the component i used in the program

Container container = getContentPane();

container.setLayout(null);

optMale = new JRadioButton( "Male",true );

optFemale = new JRadioButton( "Female",false );

football = new JCheckBox( "Football",false );

basket = new JCheckBox( "Basket",false );

boxing = new JCheckBox( "Boxing",false );

hockey = new JCheckBox( "Hockey",false );

rugby = new JCheckBox( "Rugby",false );

judo = new JCheckBox( "Judo",false );

karate = new JCheckBox( "Karate", false );

gym = new JCheckBox( "Gym" ,false );

swiming = new JCheckBox( "Swiming", false );

westling = new JCheckBox( "Westling" ,false );

lbname = new JLabel( "Name" );

lbsurname = new JLabel( "Surname" );

lbaddress = new JLabel( "Address" );

lbpostcode = new JLabel( "Post Code" );

lbphone = new JLabel( "Phone" );

lburl = new JLabel( "Url" );

lbdate = new JLabel( "Date Joined" );

jLabel = new JLabel("View all menber's records");

jLabel2 = new JLabel("Record saved");

txtname = new JTextField();

txtsurname = new JTextField();

txtaddress = new JTextField();

txtpostcode = new JTextField();

txtphone = new JTextField();

txturl = new JTextField();

txtdate = new JTextField();

output = new JTextArea(20, 200);

display = new JTextArea(20, 370);

displayall = new JButton( "Display all member's records" );

submit = new JButton( "Submit" );

clear = new JButton( "Clear" );

exit = new JButton( "Exit...");

container.add(optMale);

optMale.setBounds(320, 30, 60, 24);

optMale.addItemListener( rhandler );

container.add(optFemale);

optFemale.setBounds(410, 30, 66, 24);

optFemale.addItemListener( rhandler );

radioGroup = new ButtonGroup();

radioGroup.add( optMale );

radioGroup.add( optFemale );

container.add(football);

football.setBounds(320, 80, 70, 24);

football.addItemListener( rhandler );

container.add(basket);

basket.setBounds(410, 100, 90, 24);

basket.addItemListener( rhandler );

container.add(boxing);

boxing.setBounds(320, 100, 70, 24);

boxing.addItemListener( rhandler );

container.add(hockey);

hockey.setBounds(410, 80, 70, 24);

hockey.addItemListener( rhandler );

container.add(rugby);

rugby.setBounds(320, 120, 80, 24);

rugby.addItemListener( rhandler );

container.add(judo);

judo.setBounds(410, 120, 60, 24);

judo.addItemListener( rhandler );

container.add(karate);

karate.setBounds(320, 140, 80, 24);

karate.addItemListener( rhandler );

container.add(gym);

gym.setBounds(410, 140, 60, 24);

gym.addItemListener( rhandler );

container.add(swiming);

swiming.setBounds(320, 160, 80, 24);

swiming.addItemListener( rhandler );

container.add(westling);

westling.setBounds(410, 160, 80, 24);

westling.addItemListener( rhandler );

container.add(lbname);

lbname.setBounds(40, 30, 33, 16);

container.add(lbsurname);

lbsurname.setBounds(40, 50, 60, 16);

container.add(lbaddress);

lbaddress.setBounds(40, 70, 60, 16);

container.add(lbpostcode);

lbpostcode.setBounds(40, 90, 60, 16);

container.add(lbphone);

lbphone.setBounds(40, 110, 50, 16);

container.add(lburl);

lburl.setBounds(40, 130, 60, 16);

container.add(lbdate);

lbdate.setBounds(40, 150, 70, 16);

container.add( jLabel );

jLabel.setBounds(20, 355, 149, 16);

container.add( jLabel2 );

jLabel2.setBounds(20, 185, 150, 16);

container.add(txtname);

txtname.setBounds(110, 30, 170, 20);

container.add(txtsurname);

txtsurname.setBounds(110, 50, 170, 20);

container.add(txtaddress);

txtaddress.setBounds(110, 70, 170, 20);

container.add(txtpostcode);

txtpostcode.setBounds(110, 90, 170, 20);

container.add(txtphone);

txtphone.setBounds(110, 110, 170, 20);

container.add(txturl);

txturl.setBounds(110, 130, 170, 20);

container.add(txtdate);

txtdate.setBounds(110, 150, 170, 20);

panel = new JPanel();

panel.setBounds(20, 200, 500, 150);

panel.setLayout( new GridLayout(1, 1));

output.setBackground(new java.awt.Color(102, 255, 204));

output.setEditable(false);

output.setFont( new Font ( "Arial", Font.BOLD, 11));

panel.add( new JScrollPane(output ));

container.add( panel );

panel2 = new JPanel();

panel2.setBounds(20, 370, 500, 180 );

panel2.setLayout( new GridLayout( 1, 1 ));

display.setBackground(new java.awt.Color(102, 255, 204));

display.setFont( new Font ( "Arial", Font.BOLD, 11));

display.setEditable(false);

panel2.add( new JScrollPane( display ));

container.add( panel2 );

panel3 = new JPanel();

panel3.setBorder(new javax.swing.border.TitledBorder("Select sport"));

panel3.setBounds(300, 60, 220, 130);

container.add(panel3);

panel4 = new JPanel();

panel4.setBorder(new javax.swing.border.TitledBorder("Gender"));

panel4.setBounds(300, 10, 220, 50);

container.add(panel4);

panel5 = new JPanel();

panel5.setBorder(ne小金体育充值网址w javax.swing.border.TitledBorder("Member's details"));

panel5.setBounds(20, 10, 280, 180);

container.add(panel5);

container.add( displayall );

displayall.setBounds小金体育充值网址( 95, 555, 200, 26 );

displayall.addActionListener( handler );

container.add(submit);

submit.setBounds(305, 555, 74, 26);

submit.addActionListener( handler );

container.add(clear);

clear.setBounds(385, 555, 64, 26);

clear.addActionListener( handler );

container.add(exit);

exit.setBounds(455, 555, 64, 26);

exit.addActionListener( handler );

setSize( 550, 620 );

setResizable( false );

show();

}

public static void main(String args[]) {

new JavacourseworkPart2().show();

}

private class RadioButtonHandler implements ItemListener {

public void itemStateChanged( ItemEvent event ){

sex = "";

sport = "";

if (optMale.isSelected()){

sex = "Male";

}

if( optFemale.isSelected()) {

sex = "Female";

}

if(football.isSelected() ){

sport = sport + "Football " +"";

}

if(basket.isSelected() ){

sport = sport + "Basket " +"";

}

if( boxing.isSelected() ){

sport = sport + "Boxing " +"";

}

if(hockey.isSelected() ){

sport = sport + "Hockey " +"";

}

if( rugby.isSelected() ){

sport = sport + "Rugby " +"";

}

if( judo.isSelected() ){

sport = sport + "Judo "+ " ";

}

if( karate.isSelected() ){

sport = sport + "Karate " +"";

}

if( gym.isSelected() ){

sport = sport + "Gym ";

}

if( swiming.isSelected() ){

sport = sport + "Swiming " +"";

}

if( westling.isSelected() ){

sport = sport + "Westling ";

}

repaint();

}

}

private class ActionEventHandler implements ActionListener {

public void actionPerformed( ActionEvent event ){

if (event.getSource() == submit ){

try

{

nm = txtname.getText();

sn = txtsurname.getText();

add = txtaddress.getText();

pc = txtpostcode.getText();

ph = txtphone.getText();

ur = txturl.getText();

dt = txtdate.getText();

disp = ("\n\tSex :"+ "\t" + sex + "\tDate Joined : " + dt + "\n\tSport played :" + "\t" + sport +"\n\tName :" + "\t" + nm + "\n\tSurname :"

+"\t" + sn + "\n\tAddress :"+"\t" + add + "\n\tPost Code :"+ "\t"+

pc + "\n\tPhone :"+"\t" + ph + "\n\tWeb :"+"\t" + ur );

// JOptionPane.showMessageDialog( null, "Thank you for submiting your details");

JOptionPane.showMessageDialog( null, "Thank you for submitting");

output.setText( disp );

writeText();

}

catch(Exception e)

{

//JOptionPane.sho小金体育充值网址wMessageDialog( );

}

}

else if ( event.getSource() == clear ){ // Clear all the data from application

txtname.setText("");

txtsurname.setText("");

txtaddress.setText("");

txtpostcode.setText("");

txtphone.setText("");

txturl.setText("");

txtdate.setText("");

output.setText("");

display.setText("");

}

else if( event.getSource() == displayall ){

readText(); // Call method readText

}

else if( event.getSource() == exit) { // Exit the program

messageDialog(); // Call method messageDialog

}

}

}

public void readText() { //Method to read text from "program.txt"

String s;

s = ReadAndWrite.readTextFile("program.txt");

display.setText(s);

}

public void writeText() { //Method to write text into "program.txt"

String writing;

writing = ReadAndWrite.writeTextFile( disp + "\n\t=============================================================" );

System.out.println(disp);

}

public void messageDialog(){ //Method to ask user for confirmation of quiting the program

int n = JOptionPane.showConfirmDialog(

null,

"Do you really want to Quit this program?",

"Sport Membership",

JOptionPane.YES_NO_OPTION);

if( n == JOptionPane.YES_OPTION){

System.out.println("\nThanx for using this software,"

+"\nDesigned and Implemented by Henry");

System.exit( 0 );

}

}

}

//End of program

ReadAndWrite.java

import java.io.*;

class ReadAndWrite {

static String s;

public static String readTextFile(String filename) {

BufferedReader inFile;

String line, s = "";

try {

inFile = new BufferedReader(new FileReader(filename));

while ( (line = inFile.readLine()) != null ){

s = s + line + "\n";

}

inFile.close();

}

catch (IOException e){

System.out.println("Error in file " + filename + " : " +

e.toString() );

System.exit(1);

}

return s;

}

public static String writeTextFile( String writefile ){

try {

File file = new File("program.txt");

FileOutputStream fout = new FileOutputStream( file, true );

PrintStream myOutput = new PrintStream(fout);

myOutput.println( writefile );

myOutput.flush();

myOutput.close();

}

catch (IOException e) {

System.out.println("Error writing file: " + e);

System.exit(1);

}

return writefile;

}

}

program.txt

Sex : Male Date Joined : 10/01/2001

Sport played : BasketBoxingJudoKarateGym

Name : Henry

Surname : Tshobo

Address : 66 Macaulay road

Post Code : E6 3BL

Phone : 0208 208 3310

Web : www.henry.com

=============================================================

Sex : Male Date Joined : 10/11/2003

Sport played : JudoWestling

Name : Erick

Surname : Johnson

Address : 6 Keslake road

Post Code : NW6 3BL

Phone : 0208 208 3310

Web : www.eric.com

=============================================================

Sex : Male Date Joined : 02/09/2001Sport played : Football

Name : Eric

Surname : Mcaine

Address : 99 Queens Garden, Bayswater

Post Code : W2 3BA

Phone : 0207 123 4567

Web : www.eric.co.uk

=============================================================

Sex : Male Date Joined : 10/12/2001

Sport played : BoxingKarateSwiming

Name : Francis

Surname : George

Address : 17 North West Av

Post Code : NW6 6DF

Phone : 0777 600 25 58

Web : www.francisgeorge.com

=============================================================

Sex : Female Date Joined : 25/05/2002

Sport played : Gym Swiming

Name : Tamela

Surname : Young

Address : 547 Monkeybird , Dallas

Post Code : TX69854

Phone : 00214 54101245

Web : www.tam.com

=============================================================

Sex : null Date Joined :

Sport played : null

Name :

Surname :

Address :

Post Code :

Phone :

Web :

=============================================================

Sex : Male Date Joined : 24/02/2005

Sport played : FootballBasketHockeyRugbyJudoKarateGym

Name : Tom

Surname : Halle

Address : 32 Longmore Av

Post Code : EN5

Phone : 0208 44121547

Web : www.tom.com

=============================================================

Sex : null Date Joined :

Sport played : null

Name :

Surname :

Address :

Post Code :

Phone :

Web :

=============================================================

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

您可能还会对下面的文章感兴趣: