📄 printcode.txt
字号:
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
client1 c = new client1();
String PrintData="序号 卡通号 购物金額 消費日期 消費时間 消費物品\r\n";
int Count=0;
String[][] trydata = new String[jTable1.getRowCount()][6];
int xx = 0;
for (int i = 0; i < jTable1.getRowCount(); i = i + 1) {
if ((String) jTable1.getValueAt(i, 0) == null) {
break;
}
String[] data3 = {(String) jTable1.getValueAt(i, 0), (String) jTable1.getValueAt(i, 1), (String) jTable1.getValueAt(i, 2), (String) jTable1.getValueAt(i, 3), (String) jTable1.getValueAt(i, 4), (String) jTable1.getValueAt(i, 5),};
for (int x = 0; x < 1; x++) {
for (int j = 0; j < trydata[x].length; j++) {
trydata[xx][j] = data3[j];
String[] row = {data3[j]};
for (int z = 0; z < row.length; z++) {
Count=Count+1;
PrintData=PrintData+row[z]+" ";
if(Count==6)
{
PrintData=PrintData+"\r\n";
Count=0;
}
}
}
}
xx = xx + 1;
}
JFrame frame = new JFrame("打印");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextArea textArea=new JTextArea();
JScrollPane pane =new JScrollPane(textArea);
frame.add(pane, BorderLayout.CENTER);
textArea.setText(PrintData);
JButton button=new JButton("打印");
frame.add(button, BorderLayout.SOUTH);
ActionListener listener = new ActionListener(){
public void actionPerformed(ActionEvent e)
{try
{textArea.print();}
catch (PrinterException pe)
{System.err.println("打印失败...");}
}
};
button.addActionListener(listener);
frame.setSize(250, 150);
frame.setVisible(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -