Aplikasi Cetak Struk PLN Prabayar
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import java.awt.GridLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.*;
import javax.swing.*;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.*;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.awt.*;
import java.awt.event.*;
public class pln extends Frame {
private JLabel pie;
private JLabel x;
public pln(String title) {
super(title);
// JLabel lbltitle = new JLabel("STRUK TOKEN");
// lbl8.setFont(new Font(lbl8.getFont().getName(), lbl8.getFont().getStyle(), 20));
// String s[]={"5115100139",
// "5115100138",
// "5115100141",
// "5115100140"};
JTextField textField1 = new JTextField(20);
Font medFont = textField1.getFont().deriveFont(Font.PLAIN, 20f);
textField1.setFont(medFont);
JLabel lbl1 = new JLabel("ID PELANGGAN ");
lbl1.setFont(new Font(lbl1.getFont().getName(), lbl1.getFont().getStyle(), 20));
JPanel firstPanel = new JPanel();
firstPanel.setBackground(Color.yellow);
firstPanel.add(lbl1);
firstPanel.setLayout(new FlowLayout());
firstPanel.add(textField1);
JTextField textField2 = new JTextField(20);
Font medFont2 = textField2.getFont().deriveFont(Font.PLAIN, 20f);
textField2.setFont(medFont2);
JLabel lbl2 = new JLabel("NAMA ");
lbl2.setFont(new Font(lbl2.getFont().getName(), lbl2.getFont().getStyle(), 20));
JPanel thirdPanel = new JPanel();
thirdPanel.setBackground(Color.yellow);
thirdPanel.add(lbl2);
thirdPanel.setLayout(new FlowLayout());
thirdPanel.add(textField2);
JComboBox comboBox1 = new JComboBox(new Object[]{"20.000 ",
"30.000", "50.000", "75.000", "100.000","125.000","150.000"});
JLabel lbl3 = new JLabel("STATUS(PLN) ");
lbl3.setFont(new Font(lbl3.getFont().getName(), lbl2.getFont().getStyle(), 20));
JLabel lbl4 = new JLabel(" ");
JPanel fourthPanel = new JPanel();
fourthPanel.setBackground(Color.yellow);
fourthPanel.add(lbl3);
fourthPanel.add(comboBox1);
fourthPanel.add(lbl4);
JComboBox comboBox2 = new JComboBox(new Object[]{"R-1/450","R-1/900","R-1/1300","R-1/2200","B-1/450","B-1/900","B-1/1300 ",
"B-1/2200", "S-1/450", "S-1/900", "S-1/1300","S-1/2200","I-1/450","I-1/900","I-1/1300","I-1/2200"});
JLabel lbl5 = new JLabel("TARIF/DAYA ");
lbl5.setFont(new Font(lbl5.getFont().getName(), lbl5.getFont().getStyle(), 20));
JLabel lbl6 = new JLabel(" ");
JPanel fifthPanel = new JPanel();
fifthPanel.setBackground(Color.yellow);
fifthPanel.add(lbl5);
fifthPanel.add(comboBox2);
fifthPanel.add(lbl6);
JTextField textField3 = new JTextField(20);
Font medFont3 = textField3.getFont().deriveFont(Font.PLAIN, 20f);
textField3.setFont(medFont2);
JLabel lbl7 = new JLabel("TOKEN ");
lbl7.setFont(new Font(lbl7.getFont().getName(), lbl7.getFont().getStyle(), 20));
JPanel secPanel = new JPanel();
secPanel.setBackground(Color.yellow);secPanel.add(lbl7);
secPanel.setLayout(new FlowLayout());
secPanel.add(textField3);
String input3 = textField3.getText();
JTextField textField4 = new JTextField(20);
Font medFont4 = textField4.getFont().deriveFont(Font.PLAIN, 20f);
textField4.setFont(medFont4);
JLabel lbl8 = new JLabel("HARGA JUAL ");
lbl8.setFont(new Font(lbl8.getFont().getName(), lbl8.getFont().getStyle(), 20));
JPanel sixPanel = new JPanel();
sixPanel.setBackground(Color.yellow);sixPanel.add(lbl8);
sixPanel.setLayout(new FlowLayout());
sixPanel.add(textField4);
String input4 = textField4.getText();
JButton print = new JButton("PRINT");
JButton clear = new JButton("CLEAR");
JButton exit = new JButton("EXIT");
JPanel sevPanel = new JPanel();
//sevPanel.setLayout(null);
print.setSize(50,30);
clear.setSize(40,30);
exit.setSize(40,30);
sevPanel.setBackground(Color.yellow);sevPanel.add(print);
sevPanel.add(clear);
sevPanel.add(exit);
sevPanel.setSize(50,60);
print.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// int mark=0;
String input1 = textField1.getText();
String input2 = textField2.getText();
String input3 = textField3.getText();
String input4 = textField4.getText();
String inputcom1 = (String) comboBox1.getSelectedItem();
String inputcom2 = (String) comboBox2.getSelectedItem();
JOptionPane.showMessageDialog(null,""+input1+"\n"+input2+"\n"+inputcom1+"\n"+input3+"\n"+input4+"",
"STRUK TRANSAKSI",JOptionPane.PLAIN_MESSAGE);
}
}
);
clear.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
textField1.setText("");
textField2.setText("");
textField3.setText("");
textField4.setText("");
}
}
);
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
);
Icon pie = new ImageIcon("D:/OutputFF/pln.png");
x = new JLabel(pie,SwingConstants.LEFT);
JFrame frame = new JFrame();
frame.getContentPane().setBackground(Color.yellow);
frame.setBackground(Color.yellow);
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(x);
frame.add(firstPanel);
frame.add(thirdPanel);
frame.add(fourthPanel);
frame.add(fifthPanel);
frame.add(secPanel);
frame.add(sixPanel);
frame.add(sevPanel);
frame.pack();
frame.setSize(600,600);
frame.setLocation(150, 150);
frame.setVisible(true);
frame.setResizable(false);
}
// public static void main(String[] args) {
// pln frame = new pln("TRANSAKSI PLN");
// }
}
Output:








