Skip to content

Commit

Permalink
add friday
Browse files Browse the repository at this point in the history
  • Loading branch information
raipen committed Jun 19, 2022
1 parent 3de7494 commit 62141af
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 0 deletions.
10 changes: 10 additions & 0 deletions #finalTest_Friday/Q2_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ha-rin red 1
so-won green 6
young-jin red 7
won-seok blue 5
so-hee blue 8
su-bin red 2
min-su green 4
su-zy red 9
ji-soo blue 3
hye-jin green 0
69 changes: 69 additions & 0 deletions #finalTest_Friday/src/KtxReservationApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import java.awt.*;
import java.awt.event.*;
import java.util.HashMap;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.*;

interface KtxReservationCallback{
void updateSeat(String seat,int type);
}

public class KtxReservationApp extends JFrame{
private HashMap<String, JLabel> seat = new HashMap();
public KtxReservationApp() {

setTitle("KTX 예약 시스템");
setSize(700,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());

JLabel top = new JLabel("KTX 좌석 현황");
contentPane.add(top,BorderLayout.NORTH);

Container center = new JPanel();
center.setLayout(new GridLayout(4,10));
for(char i='D';i>='A';i--) {
for(int j=1;j<=10;j++) {
String temp = i+Integer.toString(j);
System.out.println(temp);
JLabel tempLabel = new JLabel(temp);
tempLabel.setBackground(Color.WHITE);

seat.put(temp,tempLabel);
center.add(tempLabel);
}
}
contentPane.add(center,BorderLayout.CENTER);

JButton button = new JButton("예약 시작");
contentPane.add(button,BorderLayout.SOUTH);

KtxSeat ktxSeat = new KtxSeat();
//스레드 설정
// ktxSeat.setCallback(new KtxReservationCallback() {
// @Override
// public void updateSeat(String seat,int type) {
// top.setText("스레드 실행됨"+seat);
// }
// });

button.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
button.setEnabled(false);
//ktxSeat.start();
}
});
setVisible(true);
}

public static void main(String[] args) {
System.out.println("시작");
new KtxReservationApp();
}
}
7 changes: 7 additions & 0 deletions #finalTest_Friday/src/KtxSeat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import java.util.*;

public class KtxSeat{
private HashMap<String, Integer> seat;
private HashMap<String, String> owner;

}
12 changes: 12 additions & 0 deletions #finalTest_Friday/src/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

public class Person extends Thread{
KtxReservationCallback callback;

public void setCallback(KtxReservationCallback callback) {
this.callback = callback;
}

public void run() {
callback.updateSeat("asdf", 1);
}
}
170 changes: 170 additions & 0 deletions #finalTest_Friday/src/Q2/Q2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package Q2;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;

public class Q2 extends JFrame implements ActionListener, Runnable
{
// implement your code.
public static HashMap<Integer, String> studName;
public static HashMap<Integer, Color> studColor;
public static JPanel seat;
private JButton startBtn;

public static void main(String[] args)
{
// implement your code.
Q2 attendance = new Q2();
attendance.setVisible(true);
}

public Q2()
{
super("Attendence");
setSize(800, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());

try
{
Scanner f = new Scanner(new FileInputStream("./Q2_data.txt"));

studName = new HashMap<>();
studColor = new HashMap<>();

String name, color;
int seat;
Color theColor;

while (f.hasNextLine())
{
name = f.next();
color = f.next();
seat = f.nextInt();

switch (color)
{
case "red":
theColor = Color.RED;
break;
case "blue":
theColor = Color.BLUE;
break;
case "green":
theColor = Color.GREEN;
break;
default:
theColor = Color.BLACK;
}

studName.put(seat, name);
studColor.put(seat, theColor);
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}

JPanel top = new JPanel();
top.setBackground(Color.WHITE);
JLabel welcome = new JLabel("Welcome to Java Programming class!");
top.add(welcome);
add(top, BorderLayout.NORTH);

seat = new JPanel();
seat.setLayout(new GridLayout(1, 10));

JPanel bottom = new JPanel();
bottom.setBackground(Color.WHITE);
startBtn = new JButton("Let's start!");
startBtn.addActionListener(this);
bottom.add(startBtn);
add(bottom, BorderLayout.SOUTH);

setVisible(true);
}

public void paint(Graphics g)
{
super.paint(g);
for (int i = 0; i < 10; i++)
{
g.setColor(Color.BLACK);
g.drawString(studName.get(i), 10 + (79 * i), 69);
g.setColor(studColor.get(i));
g.fillRect(5 + (79 * i), 70, 79, 79);

}
}

public void run()
{
repaint();
try
{
Thread.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
}

@Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == startBtn)
{
runnn();
}
}

public void runnn()
{
thr[] t = new thr[10];
for (int i = 0; i < 10; i++)
{
t[i] = new thr(studName, studColor, i);
Thread th = new Thread(t[i]);
th.start();
}
}

public class thr implements Runnable
{
public HashMap<Integer, String> name;
public HashMap<Integer, Color> color;
int key;

public thr(HashMap<Integer, String> n, HashMap<Integer, Color> c, int k)
{
name = n;
color = c;
key = k;
}

public void run()
{

}

public void paint(Graphics g)
{
//super.paint(g);
g.setColor(Color.BLACK);
g.drawString(studName.get(key), 10 + (79 * key), 69);
g.setColor(studColor.get(key));
g.fillRect(5 + (79 * key), 70, 79, 79);
}
}
}



0 comments on commit 62141af

Please sign in to comment.