| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 497 人关注过本帖
标题:[求助]关于异常处理
只看楼主 加入收藏
鹏举
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-6-6
收藏
 问题点数:0 回复次数:1 
[求助]关于异常处理

刚开始学JAVA比较菜,帮忙给加入异常处理功能
本程序是实现数据加密的,当输入为空,或者含有非数字字符进行异常处理


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class encrypt extends JFrame
{

private JLabel beforeencryptJLabel;
private JTextField beforeencryptJTextArea;
private JLabel afterencryptJLabel;
private JTextArea afterencryptJTextArea;
private JButton encryptJButton;

public encrypt()
{
createUserInterface();

}


private void createUserInterface()
{

Container contentPane = getContentPane();
contentPane.setBackground( Color.YELLOW );
contentPane.setLayout(null);


beforeencryptJLabel = new JLabel();
beforeencryptJLabel.setBounds( 16, 16, 156, 24 );
beforeencryptJLabel.setText( "加密前数据:" );
beforeencryptJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 20 ) );
contentPane.add( beforeencryptJLabel );


beforeencryptJTextArea = new JTextField();
beforeencryptJTextArea.setBounds( 20,60,300,30 );

afterencryptJLabel = new JLabel();
afterencryptJLabel.setBounds( 16, 130, 156, 24 );
afterencryptJLabel.setText( "加密后数据:" );
afterencryptJLabel.setFont( new Font( "SansSerif", Font.PLAIN, 20 ) );
contentPane.add( afterencryptJLabel );

String str="";
afterencryptJTextArea = new JTextArea( str);
afterencryptJTextArea.setBounds( 20, 160, 300, 100 );

contentPane.add( beforeencryptJTextArea );
contentPane.add( afterencryptJTextArea );


encryptJButton = new JButton();
encryptJButton.setBounds( 316, 16, 60, 24 );
encryptJButton.setText( "加密" );
contentPane.add( encryptJButton );
encryptJButton.addActionListener(
new ActionListener()// anonymous inner class
{
// event handler called when encryptbutton is clicked
public void actionPerformed( ActionEvent event )
{
encryptJButtonActionPerformed( event );

}

} // end anonymous inner class

); // end call to addActionListener


// set properties of application's window
setTitle( "encrypt data" ); // set title bar text
setSize( 400, 320 ); // set window size
setVisible( true ); // display window


}

private void encryptJButtonActionPerformed( ActionEvent event )
{
afterencryptJTextArea.setText("");

String s;
int t,i;
long n;
n=Long.parseLong(beforeencryptJTextArea.getText());
s=String.valueOf(n);
t=s.length();

long[] a;
a=new long[t];

for(i=0;i<t;i++)
a[i]=Long.parseLong(String.valueOf(s.charAt(i)));
for(i=0;i<t;i++)
{ a[i]=(a[i]+7)%10;}
for(i=0;i<t;i++)
afterencryptJTextArea.append(String.valueOf(a[i]));
}

// main method
public static void main( String[] args )
{
encrypt application = new encrypt();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

} // end method main

} // end class encrypt

搜索更多相关主题的帖子: 异常 数据加密 private public import 
2007-06-16 16:50
鹏举
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-6-6
收藏
得分:0 
问题已解决,谢谢路过的每一位

To strive,to seek,to find and not to yield!
2007-06-16 18:56
快速回复:[求助]关于异常处理
数据加载中...
 
   



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

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