package tast2;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.CardLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.Scanner;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
public class A2 extends JFrame {
private JPanel contentPane;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
A2 frame = new A2();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public A2() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel label = new JLabel("\u663E\u793A");
label.setBounds(146, 144, 167, 15);
contentPane.add(label);
JButton btnNewButton = new JButton("\u786E \u5B9A");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String s ;
try {
s = textField.getText().trim();
for(int i =0;i
char charAt = s.charAt(i);
if(!Character.isDigit(charAt) && charAt != ' ') {
JOptionPane.showMessageDialog(null,"输入包含非数子内容");
textField.setText("");
return ;
}
}
String[] numStr = s.split("{1,}");
int[] numArray = new int[numStr.length];
//转换输入为整数数组
for(int i =0;i
numArray[i]=Integer.valueOf(numStr[i]);
}
int min = numArray[0];
for(int j=0;j
if(min>numArray[j]) {
min=numArray[j];
}
}
label.setText("最小数为:"+min);
System.out.println(s);
}catch(NullPointerException e) {
e.printStackTrace();
}
}
});
btnNewButton.setBounds(180, 92, 69, 23);
contentPane.add(btnNewButton);
textField = new JTextField();
textField.setBounds(121, 33, 226, 21);
contentPane.add(textField);
textField.setColumns(10);
}
}