자바 네트워크로 서버 접속시 다음과같은프로그램 실행되는것좀 해결해주세요..
은솔
퍼즐게임 프로그램인데요
네트워크로 서버에 접속하면 퍼즐프로그램이 시작되고
시작할때 사용자 이름받는데 그걸 서버에 파일로 저장하는것 까지 해결부탁드립니다..
//Puzzle 클래스
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class NameStart extends JFrame implements ActionListener{
private JLabel result = new JLabel();
private JTextField name;
JButton start;
JButton end;
public NameStart(){
result.setText(사용자이름);
name = new JTextField(15);
FlowLayout fl = new FlowLayout(FlowLayout.CENTER, 10,10);
start = new JButton(시작);
end = new JButton(종료);
Container ct = getContentPane();
ct.add(result);
ct.setLayout(fl);
ct.add(name);
//ct.setLayout(new FlowLayout());
ct.add(start);
ct.add(end);
//ct.add(result);
start.addActionListener(this);
end.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
Object source = e.getSource();
if (source == start)
{
Puzzle gld = new Puzzle();
gld.setTitle(Puzzle Game);
gld.setSize(600,450);
gld.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gld.setVisible(true);
this.setVisible(false);
Time t = new Time();
t.start();
}
if (source == end)
{
this.setVisible(false);
}
}
}
public class Puzzle extends JFrame{
ImageIcon[] picture = {
new ImageIcon(통키.jpg),
new ImageIcon(통키.jpg),
new ImageIcon(999.jpg),
new ImageIcon(999.jpg),
new ImageIcon(둘리.jpg),
new ImageIcon(둘리.jpg),
new ImageIcon(삐삐.jpg),
new ImageIcon(삐삐.jpg),
new ImageIcon(슛돌이.jpg),
new ImageIcon(슛돌이.jpg),
new ImageIcon(스머프.jpg),
new ImageIcon(스머프.jpg),
new ImageIcon(아톰.jpg),
new ImageIcon(아톰.jpg),
new ImageIcon(울트라.jpg),
new ImageIcon(울트라.jpg),
new ImageIcon(차차.jpg),
new ImageIcon(차차.jpg),
new ImageIcon(캔디.jpg),
new ImageIcon(캔디.jpg),
new ImageIcon(코난.jpg),
new ImageIcon(코난.jpg),
new ImageIcon(푸우.jpg),
new ImageIcon(푸우.jpg),
};
static int b[]= new int[24];
int rd,num;
static int p=1;
public Puzzle(){
JPanel jp1 = new JPanel();
Container ct = getContentPane();
ct.setLayout(new BorderLayout());
jp1.setLayout(new GridLayout(4,6,5,5));
p++;
System.out.println(p =+p);
//if(p==2){
for(int i=0;i24;i++){
do{
num=0;
rd = (int)(Math.random()*24+1);
b[i]=rd;
for(int j=0;j24;j++){
if(b[i]==b[j]) num++;
}
}while(num=2);
jp1.add(new JButton(picture[b[i]-1]));
System.out.print(b[i]-1+ );
}
JPanel jp2 = new JPanel();
jp2.setLayout(new BorderLayout());
jp2.add(jp1, BorderLayout.NORTH);
jp2.add(new JTextField(시간 :),BorderLayout.CENTER);
ct.add(jp1, BorderLayout.NORTH);
ct.add(jp2, BorderLayout.SOUTH);
}
/*public Puzzle(int k){
for(int i=0;ik;i++){
c[i]=b[i]-1;
}
}*/
public static void main(String[] args) {
NameStart na = new NameStart();
na.setTitle(Puzzle Game);
na.setSize(300,120);
na.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
na.setVisible(true);
}
}
//BackScrren 클래스
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class BackScreen extends Puzzle implements ActionListener{
ImageIcon back[] = null;
JButton nat[] = null;
JPanel jp1 = new JPanel();
JPanel jp2 = new JPanel();
public BackScreen(){
//super(24); //랜덤값을 변경시켜 주지 않기 위해
back = new ImageIcon[24];
nat = new JButton[24];
try{
for(int i=0;i24;i++){
back[i] = new ImageIcon(back.jpg);
nat[i] = new JButton(back[i]);
nat[i].addActionListener(this);
}
}catch(Exception e){
System.out.printut.println(e);
}
screen();
}
public void screen(){
Container ct = getContentPane();
ct.setLayout(new BorderLayout());
jp1.setLayout(new GridLayout(4,6,5,5));
for(int i=0;i24;i++){
jp1.add(nat[i]);
}
jp2.setLayout(new BorderLayout());
jp2.add(jp1, BorderLayout.NORTH);
jp2.add(new JTextField(시간 :),BorderLayout.CENTER);
ct.add(jp1, BorderLayout.NORTH);
ct.add(jp2, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e) {
//Object source = e.getSource();
JButton source = (JButton)e.getSource();
String ac = e.getActionCommand();
if(source == nat[0]){
source.setIcon(picture[b[0]-1]);
}
if (source == nat[1]){
source.setIcon(picture[b[1]-1]);
}
if (source == nat[2]){
source.setIcon(picture[b[2]-1]);
}
if (source == nat[3]){
source.setIcon(picture[b[3]-1]);
}
if (source == nat[4]){
source.setIcon(picture[b[4]-1]);
}
if (source == nat[5]){
source.setIcon(picture[b[5]-1]);
}
if (source == nat[6]){
source.setIcon(picture[b[6]-1]);
}
if (source == nat[7]){
source.setIcon(picture[b[7]-1]);
}
if (source == nat[8]){
source.setIcon(picture[b[8]-1]);
}
if (source == nat[9]){
source.setIcon(picture[b[9]-1]);
}
if (source == nat[10]){
source.setIcon(picture[b[10]-1]);
}
if (source == nat[11]){
source.setIcon(picture[b[11]-1]);
}
if (source == nat[12]){
source.setIcon(picture[b[12]-1]);
}
if (source == nat[13]){
source.setIcon(picture[b[13]-1]);
}
if (source == nat[14]){
source.setIcon(picture[b[14]-1]);
}
if (source == nat[15]){
source.setIcon(picture[b[15]-1]);
}
if (source == nat[16]){
source.setIcon(picture[b[16]-1]);
}
if (source == nat[17]){
source.setIcon(picture[b[17]-1]);
}
if (source == nat[18]){
source.setIcon(picture[b[18]-1]);
}
if (source == nat[19]){
source.setIcon(picture[b[19]-1]);
}
if (source == nat[20]){
source.setIcon(picture[b[20]-1]);
}
if (source == nat[21]){
source.setIcon(picture[b[21]-1]);
}
if (source == nat[22]){
source.setIcon(picture[b[22]-1]);
}
if (source == nat[23]){
source.setIcon(picture[b[23]-1]);
}
}
}
// Time 클래스
import javax.swing.JFrame;
public class Time extends Thread {
public void run() {
int time = 1;
while(time2) {
try {
sleep(1000);
}catch(Exception e){}
// System.out.println(time +초후..);
time++;
}
//}
//public void dels(Puzzle pu)
//{
BackScreen b = new BackScreen();
b.setTitle(Puzzle Game);
b.setSize(600,450);
b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.setVisible(true);
//pu.setVisible(false);
}
}
-
매1혻적
소스에 주석달고.....
파일로 저장하는 부분이 어디고....
어디까지 해봤는데 무슨에러가 어떻게 나고...
여기까지 작성해주시면 제가 답변해드릴께요...
성의없는 질문에는 성의없는 답변만 달릴뿐입니다....