2024-04-03 15:10:01 | 我爱编程网
package cn.fu;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Window.Type;
public class Login 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 {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Login() {
setTitle("工具");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setToolTipText("");
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setBounds(121, 86, 194, 21);
contentPane.add(textField);我爱编程网
textField.setColumns(10);
JLabel lblNewLabel = new JLabel("请输入10位数以内的字符串");
lblNewLabel.setBounds(145, 59, 194, 15);
contentPane.add(lblNewLabel);
JButton btnNewButton = new JButton("确定");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String ca = textField.getText();
int n = ca.length();
if (n > 10) {
JOptionPane.showMessageDialog(null, "对不起,您输入的字符串长度超过10",
"错误提示", JOptionPane.ERROR_MESSAGE);
} else if (n >= 0 || n <= 10) {
JOptionPane.showMessageDialog(null, "字符串长度为" + n, "提示",
JOptionPane.PLAIN_MESSAGE);
}
}
});
btnNewButton.setBounds(172, 130, 93, 23);
contentPane.add(btnNewButton);
}
}
import java.util.Scanner;
public class aa {
public static void main(String[] args) {
int ri=0;
Scanner sc =new Scanner(System.in );
System.out.println("请输入一个数值:");
ri=sc.nextInt();
System.out.println(ri);
}
}
/*
1: 最简单的 控制台输入,然后在打印出来
2: 你可以查看JDK 直接查找Scanner 会找到很多方法
3: 必须学会使用JDK,而且要常看
*/
我爱编程网(https://www.52biancheng.com)小编还为大家带来用java编写有输入和输出功能的控制台程序,只在main函数中写程序(越简的相关内容。
import java.io.*;
public class Io
{
public static void main(String[] args)throws IOException
{
int a;
System.out.print("请输入一个整数:");
BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
a=Integer.parseInt(strin.readLine());
System.out.println("输入的数是:"+a);
Double b;
System.out.print("请输入一个double型:");
BufferedReader strin1=new BufferedReader(new InputStreamReader(System.in));
b=Double.parseDouble(strin.readLine());
System.out.println("输入的double数是:"+b);
String c;
System.out.print("请输入一个字符型:");
BufferedReader strin2=new BufferedReader(new InputStreamReader(System.in));
c=strin.readLine();
System.out.println("输入的字符是:"+c);
}
}
2025-02-01 20:24:39
2025-02-10 15:19:48
2024-01-05 14:11:24
2025-01-28 17:58:32
2024-11-22 05:08:01
2024-09-10 08:50:00