基本框架
1.类型条码为总输入
2.其他条码信息自动按顺序跳转
3.保存为文本(未编码实现,自行处理,可扩展选择目录保存)
界面![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/631e194177092962acbb6f2f04de1b1b.png)
代码
import com.sun.xml.internal.ws.api.server.Adapter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
public class ScanToll extends JFrame{
public static void main(String[] args) {
JLabel clientLabel;//客户列表标签
JLabel slot_1,slot_2,slot_3,slot_4,slot_5,slot_6;
JList clientList;//客户列表
JLabel historyLabel;//聊天记录标签
JScrollPane jScrollPane;//嵌套在聊天记录外面的一个容器,让里面的内容可以滚动
JTextArea historyContentLabel;//聊天记录显示的控件
JTextField messageText1 = new JTextField();
JTextField messageText2 = new JTextField();
JTextField messageText3 = new JTextField();
JTextField messageText4 = new JTextField();
JTextField messageText5 = new JTextField();
JTextField messageText6 = new JTextField();
JButton sendButton;//服务端发送的按钮
JFrame frame = new JFrame("Hello World!");
clientLabel = new JLabel("类型条码");
clientLabel.setBounds(80,40,100,35);
JTextField jSNText = new JTextField();
jSNText.setBounds(200,40,200,35);
ArrayList<JLabel> JlableList = new ArrayList<JLabel>();
ArrayList<JTextField> JTextList = new ArrayList<JTextField>();
for (int i=1;i<=6;i++){
//创建新JFrame
JLabel tempJLabel = new JLabel("SLOT_"+i);
JTextField tempJText = new JTextField();
//设置布局规则 区分奇数和偶数 按左右排列
if(i%2==1){
//布局在左侧 X起点左起100
tempJLabel.setBounds(100,50*i+50,250,40);
tempJText.setBounds(160,50*i+50,250,40);
}else {
tempJLabel.setBounds(500,50*(i-1)+50,250,40);
tempJText.setBounds(560,50*(i-1)+50,250,40);
}
JlableList.add(tempJLabel);
JTextList.add(tempJText);
switch (i){
case 1:
messageText1 = tempJText;
break;
case 2:
messageText2 = tempJText;
break;
case 3:
messageText3 = tempJText;
break;
case 4:
messageText4 = tempJText;
break;
case 5:
messageText5 = tempJText;
break;
case 6:
messageText6 = tempJText;
break;
}
}
JTextField finalMessageText1 = messageText2;
messageText1.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar()==KeyEvent.VK_ENTER ){
//判断类型信息 切换到第一个
finalMessageText1.requestFocus();
}
}
});
JTextField finalMessageText2 = messageText3;
messageText2.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar()==KeyEvent.VK_ENTER ){
//判断类型信息 切换到第一个
finalMessageText2.requestFocus();
}
}
});
JTextField finalMessageText3 = messageText4;
messageText3.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar()==KeyEvent.VK_ENTER ){
//判断类型信息 切换到第一个
finalMessageText3.requestFocus();
}
}
});
JTextField finalMessageText = messageText5;
messageText4.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar()==KeyEvent.VK_ENTER ){
//判断类型信息 切换到第一个
finalMessageText.requestFocus();
}
}
});
JTextField finalMessageText4 = messageText6;
messageText5.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar()==KeyEvent.VK_ENTER ){
//判断类型信息 切换到第一个
finalMessageText4.requestFocus();
}
}
});
jSNText.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar()==KeyEvent.VK_ENTER ){
//判断类型信息 切换到第一个
JTextList.get(0).requestFocus();
}
}
});
// messageText1 = new JTextField();
// messageText1.setBounds(160, 450, 250, 40);
sendButton = new JButton("保存条码");
sendButton.setBounds(800, 450, 100, 40);
//-----------代码分割线----------------
frame.setLayout(null);
frame.add(clientLabel);
frame.add(jSNText);
for (int j=0;j<JlableList.size();j++){
frame.add(JlableList.get(j));
}
for (int n=0;n<JTextList.size();n++){
frame.add(JTextList.get(n));
// JTextList.get(n).addKeyListener(new KeyAdapter() {
// @Override
// public void keyPressed(KeyEvent e) {
// //判断类型信息 切换到第一个
// if (e.getKeyChar()==KeyEvent.VK_ENTER ){
// //判断类型信息 切换到第一个
// JTextList.get(0).requestFocus();
// }
// }
// });
}
frame.add(sendButton);
//设置窗体
frame.setTitle("条码采集系统");//窗体标签
frame.setSize(1000, 600);//窗体大小
frame.setLocationRelativeTo(null);//在屏幕中间显示(居中显示)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//退出关闭JFrame
frame.setVisible(true);//显示窗体
frame.setResizable(false);
//设置监听方法
}
}