2 limm1203 limm1203 于 2016.02.08 13:19 提问

求一个java大神帮帮我啊

1200例上的一道题,,不会做了,,我上图,,图片

4个回答

enpterexpress
enpterexpress   2016.02.08 15:18

图片说明那不是有设计过程么

limm1203
limm1203 有的是算法的过程,,窗体的过程并没有-_-||
接近 2 年之前 回复
Yiran8935
Yiran8935   2016.02.08 15:48

看下swing的界面框架之类的、画出窗体、添加触发的事件就可以了啊

xctu_lmt
xctu_lmt   2016.02.08 17:48

import java.awt.*;
import java.lang.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JTextField;

import java.awt.Toolkit;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Test1 extends JPanel implements ActionListener {
JButton button;
JTextField textField;

 public Test1() {
     super(new GridLayout(2,1));
     textField = new JTextField(50);
     add(textField);
     button = new JButton("计算");
     button.setPreferredSize(new Dimension(20, 10));
     add(button);
     button.addActionListener(this);
 }
 public void actionPerformed(ActionEvent e) {
     String str1 = textField.getText();
     String[] str2=new String[5];
     int i=0,j=0,k=0,l=0;
     boolean flag1=true;
     while(i<str1.length()&&l<5){
         j=i;
         while(str1[i].equals(" ")){
             i++;
         }
         while(i<str1.length()&&~str1[i].equals(" ")){
             i++;
         }
         k=i;
         str2[l]=String.trim(str1.substring(j,k));
         l++;
     }
     int[] ii=new int[5];
     for(i=0;i<5;i++){
        j=0;
        while(j<str2[i].length()){
            if(~str2[i].substring(j,j+1).equals("0")&&~str2[i].substring(j,j+1).equals("1")&&~str2[i].substring(j,j+1).equals("2")

&&~str2[i].substring(j,j+1).equals("3")&&~str2[i].substring(j,j+1).equals("4")&&~str2[i].substring(j,j+1).equals("5")&&~str2[i].substring

(j,j+1).equals("6")&&~str2[i].substring(j,j+1).equals("7")&&~str2[i].substring(j,j+1).equals("8")&&~str2[i].substring(j,j+1).equals("9")

&&~str2[i].substring(j,j+1).equals("-")){
flag1=false;
}
j++;
}
if(flag1){
ii[i]=new Integer(str2[i]);
}
}
if(flag1){
int small_m=ii[0];
for(i=1;i<5;i++){
if(ii[i]<small_m){
small_m=ii[i];
}
}
textField.setText(new Integer(small_m).toString());
}else{
textField.setText("Input format error!");
}

 }
   /**
  * Create the GUI and show it.
  */
private static void createAndShowGUI() {
     //Create and set up the window.
     JFrame frame = new JFrame("Test1");
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     //Create and set up the content pane.
     JComponent newContentPane = new Test1();
     newContentPane.setOpaque(true); //content panes must be opaque
     frame.setContentPane(newContentPane);
     //Display the window.
     frame.pack();
     frame.setVisible(true);
}
public static void main(String[] args) {
     //Schedule a job for the event-dispatching thread:
     //creating and showing this application's GUI.
     javax.swing.SwingUtilities.invokeLater(new Runnable() {
         public void run() {
             createAndShowGUI();
         }
     });
}

}

如上,还没调试


leaf_130
leaf_130   2016.02.12 21:32

看看Java swing

Csdn user default icon
上传中...
上传图片
插入图片