资源简介

http://blog.csdn.net/placidzhang

资源截图

代码片段和文件信息

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.Jframe;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.border.MatteBorder;

import java.awt.Color;

import javax.swing.JLabel;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class ASCII extends Jframe {

private JPanel contentPane;
private JTextField txtILoveJava;

/**
 * Launch the application.
 */
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ASCII frame = new ASCII();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
 * Create the frame.
 */
public ASCII() {
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
setBounds(100 100 864 504);
contentPane = new JPanel();
contentPane.setBorder(new MatteBorder(1 1 1 1 (Color) new Color(0 0 0)));
contentPane.setLayout(new BorderLayout(0 0));
setContentPane(contentPane);

final JTextArea textArea = new JTextArea();
textArea.setBackground(new Color(176 224 230));
contentPane.add(textArea BorderLayout.CENTER);

JPanel panel = new JPanel();
contentPane.add(panel BorderLayout.SOUTH);
panel.setLayout(new BorderLayout(0 0));

txtILoveJava = new JTextField();
txtILoveJava.setText(“I love Java !“);
panel.add(txtILoveJava);
txtILoveJava.setColumns(10);

JButton submitBtn = new JButton(“\u786E\u5B9A“);
submitBtn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
textArea.setText(“ “);
String str = txtILoveJava.getText();
byte[] bytes = str.getBytes();
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] >= (byte) 0x81 && bytes[i] <= (byte) 0xfe) {
JOptionPane.showMessageDialog(null “不支持中文字符“);
break;
}
}

char[] ch = str.toCharArray();
byte[][] asc = new byte[ch.length][16];
try {
OutputStreamWriter output = new OutputStreamWriter(new FileOutputStream(“out.txt“));
for (int i = 0; i < ch.length; i++) {
FileInputStream file = new FileInputStream(“ASC16“);
int off = ch[i] * 16;
file.skip(off);
file.read(asc[i]);
file.close();
}
for (int i = 0; i < 16; i++) {
for (int id = 0; id < ch.length; id++) {
for (int j = 0; j < 8; j++) {
int bit = (asc[id][i] & (0x80 >> j)) >> (7 - j);
if (bit == 1) {
textArea.append(“*“);
output.write(“*“);
} else {
textArea.append(“ “);
output.write(“ “);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-12-12 12:31  ASCII\
     文件         301  2013-12-12 12:01  ASCII\.classpath
     文件         381  2013-12-12 12:01  ASCII\.project
     目录           0  2013-12-12 12:01  ASCII\.settings\
     文件         598  2013-12-12 12:01  ASCII\.settings\org.eclipse.jdt.core.prefs
     文件        4096  2010-06-26 21:45  ASCII\ASC16
     目录           0  2013-12-12 13:38  ASCII\bin\
     文件         672  2013-12-12 16:11  ASCII\bin\ASCII$1.class
     文件        2365  2013-12-12 16:11  ASCII\bin\ASCII$2.class
     文件        2197  2013-12-12 16:11  ASCII\bin\ASCII.class
     文件         160  2013-12-12 16:13  ASCII\out.txt
     目录           0  2013-12-12 12:01  ASCII\src\
     文件        3370  2013-12-12 13:20  ASCII\src\ASCII.java

评论

共有 条评论