若干个经典的Java小程序源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一个Java小程序源代码(反转字符串)//BorderLayoutTest.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

import javax.swing.event.*;

public class test1

{

public static void main(String[] args)

{

cloneFrame frame = new cloneFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.show();

}

}

class cloneFrame extends JFrame

{

public cloneFrame()

{

setTitle("机试程序");

setSize(600, 400);

JPanel buttonPanel = new JPanel();

buttonPanel.setBackground(new Color(56,43,85));

Button1 = new JButton("点击复制反转字符串");

Button1.addActionListener(new turnListener());

buttonPanel.add(Button1);

JPanel textPanel = new JPanel();

textPanel.setBackground(new Color(100,100,100));

field1 = new JTextField("姓名:老孙;学号:2004132028", 20);

field2 = new JTextField("反转", 20);

field2.setEditable(false);

textPanel.add(field1);

textPanel.add(field2);

JPanel tuPanel = new JPanel();

JLabel label = new JLabel(new ImageIcon("006.gif"));

tuPanel.add(label);

tuPanel.setBackground(new Color(100,100,100));

Container contentPane = getContentPane();

contentPane.add(buttonPanel, BorderLayout.SOUTH);

contentPane.add(textPanel, BorderLayout.NORTH);

contentPane.add(tuPanel, BorderLayout.CENTER);

contentPane.setBackground(new Color(100,100,100)); }

private class turnListener

implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

String gets = field1.getText();

int i = gets.length();

StringBuffer buffer = new StringBuffer(i);

for(int j=i-1;j>=0;j--)

{

buffer.append(gets.charAt(j));

}

String gets2 = buffer.toString();

field2.setText(gets2);

}

}

Container contentPane = getContentPane();

contentPane.add(buttonPanel, BorderLayout.SOUTH);

contentPane.add(textPanel, BorderLayout.NORTH);

contentPane.add(tuPanel, BorderLayout.CENTER);

contentPane.setBackground(new Color(100,100,100)); }

private class turnListener

implements ActionListener

{

public void actionPerformed(ActionEvent event)

{

String gets = field1.getText();

int i = gets.length();

StringBuffer buffer = new StringBuffer(i);

for(int j=i-1;j>=0;j--)

{

buffer.append(gets.charAt(j));

}

String gets2 = buffer.toString();

field2.setText(gets2);

}

}

private JButton Button1;

private JTextField field1;

private JTextField field2;

}

相关文档
最新文档