当前位置:网站首页>Course design summary
Course design summary
2022-06-11 04:57:00 【megaData】
index:
package megadata.zfx.test01;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
public class index {
private JLabel label3;// Shopping title
private JFrame frame;// window
private JLabel label1;// Account tag
private JTextField field1;// Enter account
private JLabel label2;// Password tags
private JPasswordField field2;// Password text
private JButton b1;// The login button
private JButton b2;// Registration button
public static void main(String[] args){
new index();
}
public index(){
setFrame();
listen();
}
public void setFrame(){
// Interface
frame = new JFrame(" Shopping system login ");
frame.setLayout(new GridLayout(5,1));
frame.setBounds(100,100,400,400);
frame.setLocationRelativeTo(null);// Set the screen to the center
ImageIcon bg = new ImageIcon("src/resource/pict.jpeg"); // Create a background picture
JLabel label=new JLabel(bg);// Add the background picture to the label
label.setBounds(100, 100,240, 36);
// Account and password , Log in to register
label3 = new JLabel(" Shopping system login ");
label3.setFont(new Font(" Song style ",Font.PLAIN,20));
label1 = new JLabel(" account number ");
field1 = new JTextField("",30);
label2 = new JLabel(" password ");
field2 = new JPasswordField("",30);
b1 = new JButton(" Sign in ");
b2 = new JButton(" register ");
JPanel d=new JPanel();
frame.add(label);
d.add(label3);
frame.add(d);
JPanel a=new JPanel();
a.add(label1);
a.add(field1);
JPanel b=new JPanel();
b.add(label2);
b.add(field2);
frame.add(a);
frame.add(b);
JPanel c=new JPanel();
c.add(b1);
c.add(b2);
frame.add(c);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public void listen(){
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
new Sign(field1.getText(), String.valueOf(field2.getPassword()), frame);
new shop1().loadFrame();
}
});
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
new register();
}
});
}
}
Print:
package megadata.zfx.test01;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Print extends Frame {
// attribute
TextArea text1 = new TextArea();
// public static void main(String[] args) {
// Print print = new Print();
// print.loadFrame();
// }
public void loadFrame(){
Label label1 = new Label(" * Sike small supermarket * ");
Label label2 = new Label(" shopping receipt ");
// The small ticket text content is preset
label1.setFont(new Font(" In black ",Font.BOLD,19));
label2.setFont(new Font(" In black ",Font.PLAIN,15));
text1.setEditable(false);// The text box is not editable
setBounds(550,250,300,400);
setLayout(new FlowLayout(FlowLayout.CENTER));
add(label1);
add(label2);
add(text1);
// Small ticket text output
for (int i = 0; i < shop1.v.size() / 4; i++) {
String name = shop1.v.get(i * 4).toString();
double price = Double.parseDouble(shop1.v.get(( i + 1) * 4 - 1).toString());
text1.append(" "+" Record " + (i + 1) + ":" + name + "," + price + " element " + "\r\n");
text1.append("---------------------------------------" + "\r\n");
}
double sum1 = 0;
for (int i = 1; i <= shop1.v.size() / 4; i++) {
sum1 = sum1 + Double.parseDouble(shop1.v.get( 4 * i - 1).toString());
}
text1.append(" "+" total " + sum1 + " element " + "\r\n");
setVisible(true);
setResizable(false);
// Implementation of window closing
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
setVisible(false);
text1.setText("");
}
});
}
}
register:
package megadata.zfx.test01;
//package login;
import com.megadata.test1.index;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class register {
JFrame frame;
private JPanel contentPanel = new JPanel();
private JButton ok = new JButton(" Make sure to register ");
private JButton back =new JButton(" Back to the login screen ");
private JLabel jLabel1 = new JLabel(" user name ");
private JLabel jLabel2 = new JLabel(" password ");
private JTextField atf = new JTextField(" The account name should not exceed 6 A word ",20);
private JTextField apw =new JTextField(" No more than 6 The number of digits ",20);
private JTextField idea =new JTextField("",30);
private static File file = new File(" Account and password .txt");
public static void main(String[] args){
new register();
}
public register(){
setFrame();
addListener();
}
public void setFrame(){
frame = new JFrame(" User registration ");
frame.setBounds(600,300,600,300);
frame.setLayout(new GridLayout(4,1));
frame.setLocationRelativeTo(null);// Set the window in the middle of the screen
// account number
JPanel panel1=new JPanel();
panel1.add(jLabel1);
panel1.add(atf);
// password
JPanel panel2=new JPanel();
panel2.add(jLabel2);
panel2.add(apw);
// Register and return
JPanel panel3=new JPanel();
panel3.add(back);
panel3.add(ok);
// Tips
JPanel panel4=new JPanel();
panel4.add(idea);
frame.add(panel1);
frame.add(panel2);
frame.add(panel3);
frame.add(panel4);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
private void addListener(){
ok.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(atf.getText().length()>6||apw.getText().length()>6||atf.getText().isEmpty()||apw.getText().isEmpty()){
idea.setText(" Input error ");
}else{
setRegister(atf.getText(),apw.getText());
idea.setText(" Registered successfully , You can continue to register or return to the login interface ");
}
}
});
back.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setVisible(false);
new index();
}
});
}
public void setRegister(String atf,String apw){
try{
BufferedWriter fileWriter=new BufferedWriter(new FileWriter(file,true));
fileWriter.write(atf+"="+apw);
fileWriter.newLine();
fileWriter.flush();
fileWriter.close();
}catch(IOException e){
System.out.println(" Input error ");
e.printStackTrace();
}
}
}
shop1:
package megadata.zfx.test01;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Vector;
// Master page class
public class shop1 extends Frame {
// attribute
TextField num1,num2,num3,num4;
static Vector<Object> v = new Vector<>();
TextArea text = new TextArea();
double sum = 0.0;
int f = 0;
// Method
public static int getVSize(){
return v.size()/4;
}
// public double getSum(int a){
// return v.
// }
public void loadFrame(){
num1 = new TextField(10);
num2 = new TextField(10);
num4 = new TextField(10);
num3 = new TextField(5);
Label label1 = new Label(" Product Name ");
Label label2 = new Label(" Number ");
Label label3 = new Label(" The unit price ");
Label label4 = new Label(" location ");
Button button = new Button(" add to ");
Button button1 = new Button(" To delete a single ");
Button button2 = new Button(" payment ");
Button button3 = new Button(" detailed list ");
Button button4 = new Button(" Clear the screen ");
text.setEditable(false); // Set the text area to be non editable
// Add a monitor
button.addActionListener(new MyAddListener());
button1.addActionListener(new MyDeleteListener());
button2.addActionListener(new MyPayListener());
button3.addActionListener(new MyPrintListener());
button4.addActionListener(new MyClearListener());
// Layout
setLayout(new FlowLayout());
setBounds(200,200,500,350);
setLocationRelativeTo(null);// Set the screen to the center
add(label1);
add(num1);
add(label2);
add(num2);
add(label3);
add(num4);
add(button);
add(label4);
add(num3);
add(button1);
add(button2);
add(button3);
add(button4);
add(text);
setVisible(true);
setResizable(false); // Fixed window size
// Implementation of window closing
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
// Monitor
private class MyAddListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
String n1 = num1.getText();
int n2 = Integer.parseInt(num2.getText());
double n3 = Double.parseDouble(num4.getText());
double n4 = n2 * n3;
// Add data into vector
v.add(n1);
v.add(n2);
v.add(n3);
v.add(n4);
// stay TestArea Area print added information
text.append(" add to " + (v.size()/4) +" Record :" + n1 + n2 + " Jin , The unit price " + n3 + " element " + "\r\n");
// Clear the input in the text box and wait for the next input
num1.setText("");
num2.setText("");
num4.setText("");
}
}
// Delete a single listener
private class MyDeleteListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
int n5 = Integer.parseInt(num3.getText());
text.append(" Delete " + n5 +" Record :" + v.get((n5 - 1) * 4) + v.get((n5 - 1) * 4 + 1) + " Jin , The unit price " + v.get((n5 - 1) * 4 + 2) + " element " + "\r\n");
for (int i = 0; i < 4; i++) {
v.remove((n5 - 1) * 4);
}
num3.setText("");
}
}
// Payment listener
private class MyPayListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
for (int i = 1; i <= v.size() / 4; i++) {
sum = sum + Double.parseDouble(v.get( 4 * i - 1).toString());
}
text.append(" You bought it " + v.size()/4 +" The total amount of each item is :" + sum + " element , Please pay , thank you ." + "\r\n");
f = 1; // Print ticket identifier
sum = 0;
}
}
// Empty monitor
private class MyClearListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
v.clear(); // Empty the container
text.setText(""); // Empty textbox
f = 0;
}
}
// Print ticket monitor
private class MyPrintListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if(f==0){
text.append(" Please check the receipt after confirming the payment " + "\r\n");
}else{
new Print().loadFrame();
}
}
}
}
Sign:
package megadata.zfx.test01;
import javax.swing.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Sign {
public static void main(String[] args){
}
public Sign(String atf, String apw, JFrame frame){
if(login(atf,apw)){
frame.setVisible(false);
}else{
JDialog mistaskeCase=new JDialog(frame," Tips ");
mistaskeCase.setBounds(600,300,600,300);
mistaskeCase.setLocationRelativeTo(null);
JTextField fileOfError=new JTextField(" Wrong account or password ",25);
mistaskeCase.add(fileOfError);
mistaskeCase.setVisible(true);
mistaskeCase.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}
public boolean login(String username,String password){
boolean flag = false;
BufferedReader lbd=null;
try{
lbd=new BufferedReader(new FileReader(" Account and password .txt"));
String line=null;
while((line=lbd.readLine())!=null){
String[] datas = line.split("=");
if(datas[0].equals(username)&& datas[1].equals(password)){
flag=true;
break;
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
assert lbd !=null;
try{
lbd.close();
}catch(IOException e){
e.printStackTrace();
}
}
return flag;
}
}
边栏推荐
- Titanic rescued - re exploration of data mining (ideas + source code + results)
- 华为设备配置BGP/MPLS IP 虚拟专用网命令
- An adaptive chat site - anonymous online chat room PHP source code
- Leetcode question brushing series - mode 2 (datastructure linked list) - 21:merge two sorted lists merge two ordered linked lists
- DL deep learning experiment management script
- Leetcode question brushing series - mode 2 (datastructure linked list) - 725 (m): split linked list in parts
- Huawei equipment is configured with cross domain virtual private network
- C language test question 3 (advanced program multiple choice questions _ including detailed explanation of knowledge points)
- Share 𞓜 jointly pre training transformers on unpaired images and text
- 董明珠称“格力手机做得不比苹果差”哪里来的底气?
猜你喜欢

PCB ground wire design_ Single point grounding_ Bobbin line bold

Lianrui: how to rationally see the independent R & D of domestic CPU and the development of domestic hardware

KD-Tree and LSH

World programming language ranking in January 2022

Best practices and principles of lean product development system
![[Transformer]On the Integration of Self-Attention and Convolution](/img/64/59f611533ebb0cc130d08c596a8ab2.jpg)
[Transformer]On the Integration of Self-Attention and Convolution

New UI learning method subtraction professional version 34235 question bank learning method subtraction professional version applet source code

华为设备配置通过GRE接入虚拟专用网

免费数据 | 新库上线 | CnOpenData全国文物商店及拍卖企业数据

Parametric contractual learning: comparative learning in long tail problems
随机推荐
[Transformer]MViTv1:Multiscale Vision Transformers
Network security construction in 5g Era
Following the wave of lack of core, Lianrui launched a number of gigabit network card solutions
Legend has it that setting shader attributes with shader ID can improve efficiency:)
Feature engineering feature dimension reduction
Yolact paper reading and analysis
【Markdown语法高级】 让你的博客更精彩(三:常用图标模板)
The 4th small class discussion class on fundamentals of information and communication
USB to 232 to TTL overview
What is the difference between gigabit network card and 10 Gigabit network card?
[Transformer]Is it Time to Replace CNNs with Transformers for Medical Images?
Yolov5 training personal data set summary
[Transformer]MViTv2:Improved Multiscale Vision Transformers for Classification and Detection
Programming Examples Using RDMA Verbs
The solution "no hardware is configured for this address and cannot be modified" appears during botu simulation
Win10+manjaro dual system installation
Use of mmdetection
[aaai 2021 timing action nomination generation] detailed interpretation of bsn++ long article
Chia Tai International: anyone who really invests in qihuo should know
C language test question 3 (program multiple choice question - including detailed explanation of knowledge points)