그래서 저는 Java 메모리/집중 게임 할당 작업을하고 있습니다. 내가 원했던만큼 얻지 못했지만 절반 밖에 완성되지 않았지만 GUI가 대부분 작동했습니다 ... 프레임에 라디오 버튼을 추가 할 때까지. JFrame (CardButtonPanelFrame)을 JPanel로 변경했기 때문에 문제가 발생한 것 같습니다. JFrame에 추가하는 JPanel에 3 개의 JPanel을 추가하려고합니다. 나는 모든 52 장의 카드가 튀어 나오도록 할 때 작은 빈 창을 띄우고있다.메모리/집중 게임 문제
기본적으로 프로젝트에서 작업 할 때 복잡성이 제어 불능 상태가되어 올바른 방향으로 나아갈 수 있다고 생각했습니다.
여기 내 주요있어 :
import javax.swing.*;
public class Project3{
public static void main(String[] args){
JFrame frame = new JFrame();
Grid game = new Grid();
frame.pack();
frame.add(game);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
그런 다음이 바깥 쪽 내가 상단에있는 라디오 버튼을 누르고 싶은 JPanel의, 중간에 카드, 결국 하단에있는 점수입니다.
import java.awt.*;
import javax.swing.*;
public class Grid extends JPanel{
public Grid(){
JPanel panel = new JPanel(); //construct a frame
CardButtonPanelFrame buttons = new CardButtonPanelFrame();
wtf choices = new wtf();
panel.setLayout(new GridLayout(3,1)); //that panel uses GridLayout
panel.add(choices);//add the panels to the Frame
panel.add(buttons);
//frame.add(scores);
add(panel);
setVisible(true);
}
}
이것은 라디오 버튼 패널입니다 ... 몇 가지 컴파일 문제가 있었고 이름을 변경하여 실험했기 때문에 wtf라는 이름을 사용했습니다. 나는 다른 플레이어 양을 아직 구현하는 방법을 알아 내려고하는 단계조차하지 못했습니다.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class wtf extends JPanel implements ActionListener {
static String zerostring = "Zero Player Game";
static String onestring = "One Player Game";
static String twostring = "Two Player Game";
public wtf() {
super(new BorderLayout());
//Create the radio buttons.
JRadioButton zeroButton = new JRadioButton(zerostring);
zeroButton.setMnemonic(KeyEvent.VK_C);
zeroButton.setActionCommand(zerostring);
JRadioButton oneButton = new JRadioButton(onestring);
oneButton.setMnemonic(KeyEvent.VK_B);
oneButton.setActionCommand(onestring);
oneButton.setSelected(true);
JRadioButton twoButton = new JRadioButton(twostring);
twoButton.setMnemonic(KeyEvent.VK_D);
twoButton.setActionCommand(twostring);
//Group the radio buttons.
ButtonGroup group = new ButtonGroup();
group.add(zeroButton);
group.add(oneButton);
group.add(twoButton);
//Register a listener for the radio buttons.
zeroButton.addActionListener(this);
oneButton.addActionListener(this);
twoButton.addActionListener(this);
//Put the radio buttons in a column in a panel.
JPanel radioPanel = new JPanel(new GridLayout(0, 1));
radioPanel.add(zeroButton);
radioPanel.add(oneButton);
radioPanel.add(twoButton);
add(radioPanel, BorderLayout.LINE_START);
setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}
/** Listens to the radio buttons. */
public void actionPerformed(ActionEvent e) {
//do something with e.getActionCommand()
}
}
그래서 두 가지 더 많은 클래스가 있지만 현재 문제가 있으며 여기를 코드의 거대한 벽으로 만드는 것을 두려워하고 있습니다. 나는 더 많은 질문이 있지만 나는 한 번에 하나씩 취할 것이므로 아무도 읽고 싶어하지 않는 페이지와 페이지를 게시하지 않을 것이라고 생각한다.
등의 내용을 모두 추가하면됩니다. –
기본적으로 또 하나의 "여기 내 코드가 있습니다. 제발 고쳐주세요." 미안 해요,하지만 그건 여기서 어떻게 작동하지 않습니다. 문제를 자세히 파악하여 도움을 줄 수있을 정도로 시간을내어주십시오. –
wtf 패널과 CardButtonPanelFrame을 더 큰 패널에 넣으려고했지만 빈 창이 하나도 나타나지 않습니다. CardButtonPanelFrame 만 가지고 사용하고 있었고 작동했습니다. – Confused