| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 706 人关注过本帖
标题:求助问题出在哪?
只看楼主 加入收藏
暗静暗静呢
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2015-6-26
结帖率:50%
收藏
 问题点数:0 回复次数:1 
求助问题出在哪?
package com.ruanko.view;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.JTextComponent;

import com.ruanko.business.FileOperation;






public class JMainFrame extends JFrame{
    private JTextField numberTextField=null;
    private JTextField nameTextFiel=null;
    private JTextField phoneTextField=null;
    private JTextField emailTextField=null;
    private JTextField addressTextField=null;
    private JButton addButton;
    public  JMainFrame(){
        
        this.setSize(620,500);
        this.setTitle("通讯录");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JLabel label=new JLabel("欢迎进入通讯录系统");
        this.getContentPane().add(label);
        this.setLocation(300,200);
        this.setLayout(new FlowLayout());
        ImageIcon imageIcon=new ImageIcon("image//Contact.png");
        Image image=imageIcon.getImage();
        this.setIconImage(image);
        
        JPanel mainPanel=new JPanel();
        
        mainPanel.add(new JLabel("联系人路径"));
        JTextField pathTextField = new JTextField(43);
        String defaultPath="F:/contacts.txt";
        pathTextField.setText(defaultPath);
        mainPanel.add(pathTextField);
        
        mainPanel.add( new Label("编号:"));
        JTextField numberTextField=new JTextField(12);
        mainPanel.add(numberTextField);
      
        mainPanel.add( new Label("姓名:"));
        JTextField nameTextField=new JTextField(12);
        mainPanel.add(nameTextField);
        
        mainPanel.add( new Label("手机号:"));
        JTextField phoneTextField=new JTextField(12);
        mainPanel.add(phoneTextField);
        
        mainPanel.add( new Label("email:"));
        JTextField emailTextField=new JTextField(12);
        mainPanel.add(emailTextField);
        
        mainPanel.add( new Label("地址:"));
        JTextField addressTextField=new JTextField(30);
        mainPanel.add(addressTextField);
        
        mainPanel.add(new JLabel("性别"));
        JRadioButton maleButton=null;
        JRadioButton femaleButton=null;
        maleButton=new JRadioButton("男");
        femaleButton=new JRadioButton("女");
        mainPanel.add(maleButton);
        mainPanel.add(femaleButton);
        ButtonGroup buttonGroup=new ButtonGroup();
        buttonGroup.add(maleButton);
        buttonGroup.add(femaleButton);
        maleButton.setSelected(true);
        
        mainPanel.add(new JLabel("关系:"));
        JComboBox relationshipBox=null;
        String[] relationship={"同事","同学","亲戚","朋友"};
        relationshipBox=new JComboBox(relationship);
        mainPanel.add(relationshipBox);
        
        addButton=new JButton("新增联系人");
        addButton.addActionListener((ActionListener) new AddContactActionListener());
        mainPanel.add(addButton);
        
        this.setContentPane(mainPanel);
    }
     class AddContactActionListener implements ActionListener {
                public void actionPerformed(ActionEvent e) {
                    String number=numberTextField.getText();
                    JTextComponent nameTextField = null;
                    String name=nameTextField.getText();
                    String phone=phoneTextField.getText();
                    String email=emailTextField.getText();
                    String address=addressTextField.getText();
                    String contactInfor=number+"##"+name+"##"+phone+"##"+email+"##"+address;// TODO Auto-generated method stub
                    String filePath="F:/contacts.txt";
                    System.out.println(contactInfor);
                    FileOperation fileoperation=new FileOperation();
                    fileoperation.saveContact(contactInfor,filePath);
                }

      public static void main(String[] args){              (为什么这里显示错误,提示去掉static,但是去掉后又不能运行了)
        JMainFrame frame=new JMainFrame();
        frame.setVisible(true);
    }
    }
}

搜索更多相关主题的帖子: private package public import null 
2015-11-27 00:00
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
程序代码:
public class JMainFrame extends JFrame{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private JTextField numberTextField=null;
//    private JTextField nameTextFiel=null;
    private JTextField phoneTextField=null;
    private JTextField emailTextField=null;
    private JTextField addressTextField=null;
    private JButton addButton;
    public  JMainFrame(){
        
        this.setSize(620,500);
        this.setTitle("通讯录");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JLabel label=new JLabel("欢迎进入通讯录系统");
        this.getContentPane().add(label);
        this.setLocation(300,200);
        this.setLayout(new FlowLayout());
        ImageIcon imageIcon=new ImageIcon("image//Contact.png");
        Image image=imageIcon.getImage();
        this.setIconImage(image);
        
        JPanel mainPanel=new JPanel();
        
        mainPanel.add(new JLabel("联系人路径"));
        JTextField pathTextField = new JTextField(43);
        String defaultPath="F:/contacts.txt";
        pathTextField.setText(defaultPath);
        mainPanel.add(pathTextField);
        
        mainPanel.add( new Label("编号:"));
        JTextField numberTextField=new JTextField(12);
        mainPanel.add(numberTextField);
       
        mainPanel.add( new Label("姓名:"));
        JTextField nameTextField=new JTextField(12);
        mainPanel.add(nameTextField);
        
        mainPanel.add( new Label("手机号:"));
        JTextField phoneTextField=new JTextField(12);
        mainPanel.add(phoneTextField);
        
        mainPanel.add( new Label("email:"));
        JTextField emailTextField=new JTextField(12);
        mainPanel.add(emailTextField);
        
        mainPanel.add( new Label("地址:"));
        JTextField addressTextField=new JTextField(30);
        mainPanel.add(addressTextField);
        
        mainPanel.add(new JLabel("性别"));
        JRadioButton maleButton=null;
        JRadioButton femaleButton=null;
        maleButton=new JRadioButton("男");
        femaleButton=new JRadioButton("女");
        mainPanel.add(maleButton);
        mainPanel.add(femaleButton);
        ButtonGroup buttonGroup=new ButtonGroup();
        buttonGroup.add(maleButton);
        buttonGroup.add(femaleButton);
        maleButton.setSelected(true);
        
        mainPanel.add(new JLabel("关系:"));
        JComboBox<String> relationshipBox=null;
        String[] relationship={"同事","同学","亲戚","朋友"};
        relationshipBox=new JComboBox<String>(relationship);
        mainPanel.add(relationshipBox);
        
        addButton=new JButton("新增联系人");
        addButton.addActionListener((ActionListener) new AddContactActionListener());
        mainPanel.add(addButton);
        
        this.setContentPane(mainPanel);
    }
     class AddContactActionListener implements ActionListener {
                public void actionPerformed(ActionEvent e) {
                    String number=numberTextField.getText();
                    JTextComponent nameTextField = null;
                    String name=nameTextField.getText();
                    String phone=phoneTextField.getText();
                    String email=emailTextField.getText();
                    String address=addressTextField.getText();
                    String contactInfor=number+"##"+name+"##"+phone+"##"+email+"##"+address;// TODO Auto-generated method stub
                    String filePath="F:/contacts.txt";
                    System.out.println(contactInfor);
//                    FileOperation fileoperation=new FileOperation();
//                    fileoperation.saveContact(contactInfor,filePath);
                }
    }
     
     public static void main(String[] args){              //为什么这里显示错误,提示去掉static,但是去掉后又不能运行了)
         JMainFrame frame=new JMainFrame();
     frame.setVisible(true);
    }
}

剑栈风樯各苦辛,别时冰雪到时春
2015-11-27 08:54
快速回复:求助问题出在哪?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028109 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved