当前位置: 技术问答>java相关
java面试测试题,20分钟内做完,有人试试吗?
来源: 互联网 发布时间:2015-08-03
本文导语: 1现在输入n个数字,以逗号,分开; 2然后可选择升或者降序排序; 3按提交键就在另一页面显示 按什么 排序,结果为, , 4 提供reset 试试了,有人做出来了吗,不妨拿代码来看看!大家一起进步! ...
1现在输入n个数字,以逗号,分开;
2然后可选择升或者降序排序;
3按提交键就在另一页面显示
按什么 排序,结果为, ,
4 提供reset
试试了,有人做出来了吗,不妨拿代码来看看!大家一起进步!
2然后可选择升或者降序排序;
3按提交键就在另一页面显示
按什么 排序,结果为, ,
4 提供reset
试试了,有人做出来了吗,不妨拿代码来看看!大家一起进步!
|
package study1;
import javax.swing.UIManager;
import java.awt.*;
public class Application1 {
boolean packFrame = false;
/**Construct the application*/
public Application1() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
/**Main method*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Application1();
}
}
package study1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Frame1 extends JFrame {
JPanel contentPane;
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
GridBagLayout gridBagLayout1 = new GridBagLayout();
int[] a;
JTextArea jTextArea1 = new JTextArea();
JCheckBox jCheckBox1 = new JCheckBox();
/**Construct the frame*/
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jButton1.setText("ok");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jButton1_mouseClicked(e);
}
});
jButton2.setText("reset");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jCheckBox1.setText("desc");
contentPane.add(jButton1, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 3), 91, 32));
contentPane.add(jTextField1, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0
,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 198, 32));
contentPane.add(jTextArea1, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0
,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(12, 0, 14, 0), 205, 44));
contentPane.add(jButton2, new GridBagConstraints(2, 1, 1, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(9, 0, 9, 3), 97, 24));
contentPane.add(jCheckBox1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_mouseClicked(MouseEvent e) {
a=splitStringByComma(this.jTextField1.getText());
Arrays.sort(a);
this.jTextArea1.setText("");
if (this.jCheckBox1.isSelected()){
for(int i=a.length-1;i>=0;i--){
this.jTextArea1.append(String.valueOf(a[i]));
}
}else{
for(int i=0;i
import javax.swing.UIManager;
import java.awt.*;
public class Application1 {
boolean packFrame = false;
/**Construct the application*/
public Application1() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
frame.pack();
}
else {
frame.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
/**Main method*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
e.printStackTrace();
}
new Application1();
}
}
package study1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class Frame1 extends JFrame {
JPanel contentPane;
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
GridBagLayout gridBagLayout1 = new GridBagLayout();
int[] a;
JTextArea jTextArea1 = new JTextArea();
JCheckBox jCheckBox1 = new JCheckBox();
/**Construct the frame*/
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
jButton1.setText("ok");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
jButton1_mouseClicked(e);
}
});
jButton2.setText("reset");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton2_actionPerformed(e);
}
});
jCheckBox1.setText("desc");
contentPane.add(jButton1, new GridBagConstraints(0, 1, 2, 1, 1.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 5, 0, 3), 91, 32));
contentPane.add(jTextField1, new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0
,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 198, 32));
contentPane.add(jTextArea1, new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0
,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(12, 0, 14, 0), 205, 44));
contentPane.add(jButton2, new GridBagConstraints(2, 1, 1, 1, 1.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(9, 0, 9, 3), 97, 24));
contentPane.add(jCheckBox1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_mouseClicked(MouseEvent e) {
a=splitStringByComma(this.jTextField1.getText());
Arrays.sort(a);
this.jTextArea1.setText("");
if (this.jCheckBox1.isSelected()){
for(int i=a.length-1;i>=0;i--){
this.jTextArea1.append(String.valueOf(a[i]));
}
}else{
for(int i=0;i