标题:[求助]关于异常处理
只看楼主
鹏举
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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-148034-1-1.html




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

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