资源描述:
《若干个经典的Java小程序源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、一个Java小程序源代码(反转字符串) //BorderLayoutTest.javaimportjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.border.*;importjavax.swing.event.*;publicclasstest1{ publicstaticvoidmain(String[]args){ cloneFrameframe=newcloneFrame(); frame.setDefaultClos
2、eOperation(JFrame.EXIT_ON_CLOSE); frame.show();}}classcloneFrameextendsJFrame{publiccloneFrame(){ setTitle("机试程序"); setSize(600,400); JPanelbuttonPanel=newJPanel(); buttonPanel.setBackground(newColor(56,43,85)); Button1=newJButton("点击复制反转字符串"); Bu
3、tton1.addActionListener(newturnListener()); buttonPanel.add(Button1); JPaneltextPanel=newJPanel(); textPanel.setBackground(newColor(100,100,100)); field1=newJTextField("姓名:老孙;学号:2004132028",20); field2=newJTextField("反转",20); field2.setEditable(false
4、); textPanel.add(field1); textPanel.add(field2); JPaneltuPanel=newJPanel(); JLabellabel=newJLabel(newImageIcon("006.gif")); tuPanel.add(label); tuPanel.setBackground(newColor(100,100,100)); ContainercontentPane=getContentPane(); contentPane.add(bu
5、ttonPanel,BorderLayout.SOUTH); contentPane.add(textPanel,BorderLayout.NORTH); contentPane.add(tuPanel,BorderLayout.CENTER); contentPane.setBackground(newColor(100,100,100));}privateclassturnListener implementsActionListener{ publicvoidactionPerformed(ActionEv
6、entevent) { Stringgets=field1.getText(); inti=gets.length(); StringBufferbuffer=newStringBuffer(i); for(intj=i-1;j>=0;j--) { buffer.append(gets.charAt(j)); } Stringgets2=buffer.toString(); fi
7、eld2.setText(gets2); }} ContainercontentPane=getContentPane(); contentPane.add(buttonPanel,BorderLayout.SOUTH); contentPane.add(textPanel,BorderLayout.NORTH); contentPane.add(tuPanel,BorderLayout.CENTER); contentPane.setBackground(newColor(100,100,100));}p
8、rivateclassturnListener implementsActionListener{ publicvoidactionPerformed(ActionEventevent) { Stringgets=f