none 个我的图像或字母(组合框除外)正在显示
none of my images or letters except my ComboBox are showing
我正在创建一个刽子手游戏,我有 body 下来,但是一旦我添加了要显示的 ComboBox none。
我已经看了一个小时了,找不到原因!它应该打印出完整的 body 和字母 a-z。我到处都看过,找不到解决方案。代码很长,因为我真的不知道什么是重要的或不重要的。 (忽略代码中的注释只是帮助我)
public class GamePanel extends JPanel implements ActionListener {
private static final long serialVersionUID = -3919093956447306405L;
static final int SCREEN_WIDTH = 600;
static final int SCREEN_HEIGHT = 600;
static final int UNIT_SIZE = 100;
static final int UNIT_SIZE2 = 19;
static final int UNIT_SIZE3 = 40;
static final int UNIT_SIZE4 = 20;
static final int UNIT_SIZE5 = 60;
// underline ^
static final int UNIT_SIZE6 = (int) 7.5;
// break between ___ fix ^
static final int UNIT_SIZE7 = 0;
// remove the image
static final int GAME_UNITS = (SCREEN_WIDTH*SCREEN_HEIGHT)/UNIT_SIZE;
Random random;
int HeadX = 400;
int HeadY = 100;
int BodyX = 430;
int BodyY = 180;
int Arm1X = 400;
int Arm1Y = 240;
int Arm2X = 460;
int Arm2Y = 240;
int Leg1X = 430;
int Leg1Y = 300;
int Leg2X = 451;
int Leg2Y = 300;
int Letter1UnderlineX = 0+ UNIT_SIZE6;
int Letter1UnderlineY = 535;
int Letter2UnderlineX = 75+ UNIT_SIZE6;
int Letter2UnderlineY = 535;
int Letter3UnderlineX = 150+ UNIT_SIZE6;
int Letter3UnderlineY = 535;
int Letter4UnderlineX = 225+ UNIT_SIZE6;
int Letter4UnderlineY = 535;
int Letter5UnderlineX = 300+ UNIT_SIZE6;
int Letter5UnderlineY = 535;
int Letter6UnderlineX = 375+ UNIT_SIZE6;
int Letter6UnderlineY = 535;
int Letter7UnderlineX = 450+ UNIT_SIZE6;
int Letter7UnderlineY = 535;
int Letter8UnderlineX = 525+ UNIT_SIZE6;
int Letter8UnderlineY = 535;
String a = ("a");
String b = ("b");
String c = ("c");
String d = ("d");
String e = ("e");
String f1 = ("f");
String g1 = ("g");
String h = ("h");
String i = ("i");
String j = ("j");
String k = ("k");
String l = ("l");
String m = ("m");
String n = ("n");
String o = ("o");
String p = ("p");
String q = ("q");
String r = ("r");
String s = ("s");
String t = ("t");
String u = ("u");
String v = ("v");
String w = ("w");
String x = ("x");
String y = ("y");
String z = ("z");
JFrame f;
public static void main(String[] args) {
System.out.println("Welcome to Hang Man!");
Start();
System.out.println("Test");
}
public static void Start(){
Scanner YesNoScanner = new Scanner(System.in);
Scanner Letter = new Scanner(System.in);
String[] letters = new String[100];
String ans = "";
int count = 0;
System.out.println("Would you like to play? (Yes - 1 | No - 2)");
int YesNo = YesNoScanner.nextInt();
if (YesNo == 1) {
System.out.println("Rules: Word MUST be less than or equal to 8 characters \n \t No SPACES in the word or subject \n \t Don't show anyone the word if its your turn for the word ");
System.out.println("You are about to start. \nDon't show anyone the word and subject your word is based off.");
System.out.println("When writing the word only write ONE letter at a time!");
System.out.println("Write 'done' when you are done writing your word.");
System.out.println("\n\nChoose a word between 1-8 characters long\n ( ONE LETTER AT A TIME [press enter after every letter])");
do {
System.out.print("Letter " + (count + 1) + ": " ) ;
ans = Letter.nextLine();
if(!ans.equalsIgnoreCase("done")) {
letters[count] = ans;
count++;
if (count == 8) {
System.out.println("Maximium letters reached");
ans = ("done");
}
}
String one = letters[0];
}while(!ans.equalsIgnoreCase ("done"));
System.out.println("\nYour word is: ");
for(int i = 0; i < count; i++) {
System.out.print(letters[i]);
}
System.out.println(" \nIs this the word you would like? (Yes - 1 | No - 2)");
}else {
System.out.println("You chose to not play. Maybe later :C");
System.exit(0);
}
Scanner YesNoScanner2 = new Scanner(System.in);
int YesNo2 = YesNoScanner2.nextInt();
if (YesNo2 == 1) {
SubjectWrite();
}else {
Start();
}
new GamePanel();
}
public static void SubjectWrite() {
Scanner Subject = new Scanner(System.in);
String ans = "";
System.out.println("Please choose a subject! (1-10 characters long)");
ans = Subject.nextLine();
System.out.println(" \nIs this the Subject you would like? (Yes - 1 | No - 2)");
System.out.println(ans);
Scanner YesNoScanner3 = new Scanner(System.in);
int YesNo3 = YesNoScanner3.nextInt();
if (YesNo3 == 1) {
System.out.println("Are you ready to play? (Yes - 1 | No - 2)");
Scanner YesNoScanner4 = new Scanner(System.in);
int YesNo4 = YesNoScanner4.nextInt();
if(YesNo4 == 1) {
for(int i = 0; i<200;i++) {
System.out.println("\n");
}
}else {
System.exit(0);
}
}else {
System.exit(0);
}
}
//new main method
public void gui() {
f = new JFrame("Title");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
f.pack();
f.setLocationRelativeTo(null);
f.setSize(618, 640);
f.setVisible(true);
String country[]={"India","Aus","U.S.A","England","Newzealand"};
JComboBox cb=new JComboBox(country);
cb.setBounds(50, 50,90,20);
f.add(cb);
f.setLayout(null);
f.setVisible(true);
}
public GamePanel(){
gui();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
draw(g);
}
private void draw(Graphics g) {
// TODO Auto-generated method stub
for(int i=0;i <SCREEN_HEIGHT/UNIT_SIZE;i++) {
g.drawLine(i*UNIT_SIZE, 0, i*UNIT_SIZE, SCREEN_HEIGHT);
g.drawLine(0, i*UNIT_SIZE, SCREEN_WIDTH, i*UNIT_SIZE);
}
int fix1 = 30;
g.setColor(Color.black);
g.setFont(new Font("BiauKai", Font.BOLD, 20));
FontMetrics metrics = getFontMetrics(g.getFont());
g.drawString(a , (SCREEN_WIDTH - metrics.stringWidth(a))-580 + fix1 , g.getFont().getSize());
g.drawString(b , (SCREEN_WIDTH - metrics.stringWidth(b))-560 + fix1 , g.getFont().getSize());
g.drawString(c , (SCREEN_WIDTH - metrics.stringWidth(c))-540 + fix1 , g.getFont().getSize());
g.drawString(d , (SCREEN_WIDTH - metrics.stringWidth(d))-520 + fix1 , g.getFont().getSize());
g.drawString(e , (SCREEN_WIDTH - metrics.stringWidth(e))-500 + fix1 , g.getFont().getSize());
g.drawString(f1 , (SCREEN_WIDTH - metrics.stringWidth(f1))-480 + fix1 , g.getFont().getSize());
g.drawString(g1 , (SCREEN_WIDTH - metrics.stringWidth(g1))-460 + fix1 , g.getFont().getSize());
g.drawString(h , (SCREEN_WIDTH - metrics.stringWidth(h))-440 + fix1 , g.getFont().getSize());
g.drawString(i , (SCREEN_WIDTH - metrics.stringWidth(i))-420 + fix1 , g.getFont().getSize());
g.drawString(j , (SCREEN_WIDTH - metrics.stringWidth(j))-400 + fix1 , g.getFont().getSize());
g.drawString(k , (SCREEN_WIDTH - metrics.stringWidth(k))-380 + fix1 , g.getFont().getSize());
g.drawString(l , (SCREEN_WIDTH - metrics.stringWidth(l))-365 + fix1 , g.getFont().getSize());
g.drawString(m , (SCREEN_WIDTH - metrics.stringWidth(m))-340 + fix1 , g.getFont().getSize());
g.drawString(n , (SCREEN_WIDTH - metrics.stringWidth(n))-320 + fix1 , g.getFont().getSize());
g.drawString(o , (SCREEN_WIDTH - metrics.stringWidth(o))-300 + fix1 , g.getFont().getSize());
g.drawString(p , (SCREEN_WIDTH - metrics.stringWidth(p))-280 + fix1 , g.getFont().getSize());
g.drawString(q , (SCREEN_WIDTH - metrics.stringWidth(q))-260 + fix1 , g.getFont().getSize());
g.drawString(r , (SCREEN_WIDTH - metrics.stringWidth(r))-240 + fix1 , g.getFont().getSize());
g.drawString(s , (SCREEN_WIDTH - metrics.stringWidth(s))-220 + fix1 , g.getFont().getSize());
g.drawString(t , (SCREEN_WIDTH - metrics.stringWidth(t))-200 + fix1 , g.getFont().getSize());
g.drawString(u , (SCREEN_WIDTH - metrics.stringWidth(u))-180 + fix1 , g.getFont().getSize());
g.drawString(v , (SCREEN_WIDTH - metrics.stringWidth(v))-160 + fix1 , g.getFont().getSize());
g.drawString(w , (SCREEN_WIDTH - metrics.stringWidth(w))-140 + fix1 , g.getFont().getSize());
g.drawString(x , (SCREEN_WIDTH - metrics.stringWidth(x))-120 + fix1 , g.getFont().getSize());
g.drawString(y , (SCREEN_WIDTH - metrics.stringWidth(y))-100 + fix1 , g.getFont().getSize());
g.drawString(z , (SCREEN_WIDTH - metrics.stringWidth(z))-80 + fix1 , g.getFont().getSize());
g.drawString(a, (SCREEN_WIDTH - metrics.stringWidth(a))-580 + fix1 , SCREEN_HEIGHT - 560);
//g.drawString(a,40,40);
g.setColor(Color.black);
g.fillOval(HeadX, HeadY, UNIT_SIZE, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(BodyX, BodyY, UNIT_SIZE3, UNIT_SIZE + UNIT_SIZE4);
g.setColor(Color.black);
g.fillRect(Arm1X, Arm1Y, UNIT_SIZE3, UNIT_SIZE2);
g.setColor(Color.black);
g.fillRect(Arm2X, Arm2Y, UNIT_SIZE3, UNIT_SIZE2);
g.setColor(Color.black);
g.fillRect(Leg1X, Leg1Y, UNIT_SIZE2, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(Leg2X, Leg2Y, UNIT_SIZE2, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(Letter1UnderlineX, Letter1UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter2UnderlineX, Letter2UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter3UnderlineX, Letter3UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter4UnderlineX, Letter4UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter5UnderlineX, Letter5UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter6UnderlineX, Letter6UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter7UnderlineX, Letter7UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter8UnderlineX, Letter8UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
- 避免将控制台输入与 GUI 混合使用;
- 你没有给你添加
GamePane
window;
- 避免
null
布局
有关更多想法,请参阅 Laying Out Components Within a Container
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.add(new GamePanel());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JTextArea rules = new JTextArea(8, 40);
rules.setWrapStyleWord(true);
rules.setLineWrap(true);
rules.append("Rules: Word MUST be less than or equal to 8 characters\n * No SPACES in the word or subject\n * Don't show anyone the word if its your turn for the word\n");
rules.append("You are about to start. \nDon't show anyone the word and subject your word is based off.");
rules.append("When writing the word only write ONE letter at a time!");
rules.append("Write 'done' when you are done writing your word.");
JOptionPane.showMessageDialog(frame, rules, "The Rules", JOptionPane.PLAIN_MESSAGE);
}
});
}
public class GamePanel extends JPanel implements ActionListener {
private static final long serialVersionUID = -3919093956447306405L;
static final int SCREEN_WIDTH = 600;
static final int SCREEN_HEIGHT = 600;
static final int UNIT_SIZE = 100;
static final int UNIT_SIZE2 = 19;
static final int UNIT_SIZE3 = 40;
static final int UNIT_SIZE4 = 20;
static final int UNIT_SIZE5 = 60;
// underline ^
static final int UNIT_SIZE6 = (int) 7.5;
// break between ___ fix ^
static final int UNIT_SIZE7 = 0;
// remove the image
static final int GAME_UNITS = (SCREEN_WIDTH * SCREEN_HEIGHT) / UNIT_SIZE;
Random random;
int HeadX = 400;
int HeadY = 100;
int BodyX = 430;
int BodyY = 180;
int Arm1X = 400;
int Arm1Y = 240;
int Arm2X = 460;
int Arm2Y = 240;
int Leg1X = 430;
int Leg1Y = 300;
int Leg2X = 451;
int Leg2Y = 300;
int Letter1UnderlineX = 0 + UNIT_SIZE6;
int Letter1UnderlineY = 535;
int Letter2UnderlineX = 75 + UNIT_SIZE6;
int Letter2UnderlineY = 535;
int Letter3UnderlineX = 150 + UNIT_SIZE6;
int Letter3UnderlineY = 535;
int Letter4UnderlineX = 225 + UNIT_SIZE6;
int Letter4UnderlineY = 535;
int Letter5UnderlineX = 300 + UNIT_SIZE6;
int Letter5UnderlineY = 535;
int Letter6UnderlineX = 375 + UNIT_SIZE6;
int Letter6UnderlineY = 535;
int Letter7UnderlineX = 450 + UNIT_SIZE6;
int Letter7UnderlineY = 535;
int Letter8UnderlineX = 525 + UNIT_SIZE6;
int Letter8UnderlineY = 535;
String a = ("a");
String b = ("b");
String c = ("c");
String d = ("d");
String e = ("e");
String f1 = ("f");
String g1 = ("g");
String h = ("h");
String i = ("i");
String j = ("j");
String k = ("k");
String l = ("l");
String m = ("m");
String n = ("n");
String o = ("o");
String p = ("p");
String q = ("q");
String r = ("r");
String s = ("s");
String t = ("t");
String u = ("u");
String v = ("v");
String w = ("w");
String x = ("x");
String y = ("y");
String z = ("z");
//
// JFrame f;
//
// public static void main(String[] args) {
//
// System.out.println("Welcome to Hang Man!");
//
// Start();
//
// System.out.println("Test");
//
// }
//
// public static void Start() {
//
// Scanner YesNoScanner = new Scanner(System.in);
// Scanner Letter = new Scanner(System.in);
// String[] letters = new String[100];
// String ans = "";
// int count = 0;
//
// System.out.println("Would you like to play? (Yes - 1 | No - 2)");
// int YesNo = YesNoScanner.nextInt();
// if (YesNo == 1) {
// System.out.println("Rules: Word MUST be less than or equal to 8 characters \n \t No SPACES in the word or subject \n \t Don't show anyone the word if its your turn for the word ");
// System.out.println("You are about to start. \nDon't show anyone the word and subject your word is based off.");
// System.out.println("When writing the word only write ONE letter at a time!");
// System.out.println("Write 'done' when you are done writing your word.");
//
// System.out.println("\n\nChoose a word between 1-8 characters long\n ( ONE LETTER AT A TIME [press enter after every letter])");
//
// do {
// System.out.print("Letter " + (count + 1) + ": ");
// ans = Letter.nextLine();
// if (!ans.equalsIgnoreCase("done")) {
// letters[count] = ans;
// count++;
// if (count == 8) {
// System.out.println("Maximium letters reached");
// ans = ("done");
//
// }
// }
// String one = letters[0];
// } while (!ans.equalsIgnoreCase("done"));
//
// System.out.println("\nYour word is: ");
// for (int i = 0; i < count; i++) {
// System.out.print(letters[i]);
// }
//
// System.out.println(" \nIs this the word you would like? (Yes - 1 | No - 2)");
//
// } else {
// System.out.println("You chose to not play. Maybe later :C");
// System.exit(0);
// }
//
// Scanner YesNoScanner2 = new Scanner(System.in);
// int YesNo2 = YesNoScanner2.nextInt();
// if (YesNo2 == 1) {
// SubjectWrite();
// } else {
// Start();
// }
//
// new GamePanel();
//
// }
//
// public static void SubjectWrite() {
// Scanner Subject = new Scanner(System.in);
// String ans = "";
//
// System.out.println("Please choose a subject! (1-10 characters long)");
//
// ans = Subject.nextLine();
//
// System.out.println(" \nIs this the Subject you would like? (Yes - 1 | No - 2)");
// System.out.println(ans);
//
// Scanner YesNoScanner3 = new Scanner(System.in);
// int YesNo3 = YesNoScanner3.nextInt();
// if (YesNo3 == 1) {
// System.out.println("Are you ready to play? (Yes - 1 | No - 2)");
// Scanner YesNoScanner4 = new Scanner(System.in);
// int YesNo4 = YesNoScanner4.nextInt();
// if (YesNo4 == 1) {
// for (int i = 0; i < 200; i++) {
// System.out.println("\n");
// }
//
// } else {
// System.exit(0);
// }
//
// } else {
// System.exit(0);
// }
//
// }
// //new main method
// public void gui() {
// f = new JFrame("Title");
// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// f.setResizable(false);
// f.pack();
// f.setLocationRelativeTo(null);
// f.setSize(618, 640);
// f.setVisible(true);
// f.add(cb);
// f.setLayout(null);
// f.setVisible(true);
// }
public GamePanel() {
String country[] = {"India", "Aus", "U.S.A", "England", "Newzealand"};
JComboBox cb = new JComboBox(country);
cb.setBounds(50, 50, 90, 20);
add(cb);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(640, 640);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
draw(g);
}
private void draw(Graphics g) {
// TODO Auto-generated method stub
for (int i = 0; i < SCREEN_HEIGHT / UNIT_SIZE; i++) {
g.drawLine(i * UNIT_SIZE, 0, i * UNIT_SIZE, SCREEN_HEIGHT);
g.drawLine(0, i * UNIT_SIZE, SCREEN_WIDTH, i * UNIT_SIZE);
}
int fix1 = 30;
g.setColor(Color.black);
g.setFont(new Font("BiauKai", Font.BOLD, 20));
FontMetrics metrics = getFontMetrics(g.getFont());
g.drawString(a, (SCREEN_WIDTH - metrics.stringWidth(a)) - 580 + fix1, g.getFont().getSize());
g.drawString(b, (SCREEN_WIDTH - metrics.stringWidth(b)) - 560 + fix1, g.getFont().getSize());
g.drawString(c, (SCREEN_WIDTH - metrics.stringWidth(c)) - 540 + fix1, g.getFont().getSize());
g.drawString(d, (SCREEN_WIDTH - metrics.stringWidth(d)) - 520 + fix1, g.getFont().getSize());
g.drawString(e, (SCREEN_WIDTH - metrics.stringWidth(e)) - 500 + fix1, g.getFont().getSize());
g.drawString(f1, (SCREEN_WIDTH - metrics.stringWidth(f1)) - 480 + fix1, g.getFont().getSize());
g.drawString(g1, (SCREEN_WIDTH - metrics.stringWidth(g1)) - 460 + fix1, g.getFont().getSize());
g.drawString(h, (SCREEN_WIDTH - metrics.stringWidth(h)) - 440 + fix1, g.getFont().getSize());
g.drawString(i, (SCREEN_WIDTH - metrics.stringWidth(i)) - 420 + fix1, g.getFont().getSize());
g.drawString(j, (SCREEN_WIDTH - metrics.stringWidth(j)) - 400 + fix1, g.getFont().getSize());
g.drawString(k, (SCREEN_WIDTH - metrics.stringWidth(k)) - 380 + fix1, g.getFont().getSize());
g.drawString(l, (SCREEN_WIDTH - metrics.stringWidth(l)) - 365 + fix1, g.getFont().getSize());
g.drawString(m, (SCREEN_WIDTH - metrics.stringWidth(m)) - 340 + fix1, g.getFont().getSize());
g.drawString(n, (SCREEN_WIDTH - metrics.stringWidth(n)) - 320 + fix1, g.getFont().getSize());
g.drawString(o, (SCREEN_WIDTH - metrics.stringWidth(o)) - 300 + fix1, g.getFont().getSize());
g.drawString(p, (SCREEN_WIDTH - metrics.stringWidth(p)) - 280 + fix1, g.getFont().getSize());
g.drawString(q, (SCREEN_WIDTH - metrics.stringWidth(q)) - 260 + fix1, g.getFont().getSize());
g.drawString(r, (SCREEN_WIDTH - metrics.stringWidth(r)) - 240 + fix1, g.getFont().getSize());
g.drawString(s, (SCREEN_WIDTH - metrics.stringWidth(s)) - 220 + fix1, g.getFont().getSize());
g.drawString(t, (SCREEN_WIDTH - metrics.stringWidth(t)) - 200 + fix1, g.getFont().getSize());
g.drawString(u, (SCREEN_WIDTH - metrics.stringWidth(u)) - 180 + fix1, g.getFont().getSize());
g.drawString(v, (SCREEN_WIDTH - metrics.stringWidth(v)) - 160 + fix1, g.getFont().getSize());
g.drawString(w, (SCREEN_WIDTH - metrics.stringWidth(w)) - 140 + fix1, g.getFont().getSize());
g.drawString(x, (SCREEN_WIDTH - metrics.stringWidth(x)) - 120 + fix1, g.getFont().getSize());
g.drawString(y, (SCREEN_WIDTH - metrics.stringWidth(y)) - 100 + fix1, g.getFont().getSize());
g.drawString(z, (SCREEN_WIDTH - metrics.stringWidth(z)) - 80 + fix1, g.getFont().getSize());
g.drawString(a, (SCREEN_WIDTH - metrics.stringWidth(a)) - 580 + fix1, SCREEN_HEIGHT - 560);
//g.drawString(a,40,40);
g.setColor(Color.black);
g.fillOval(HeadX, HeadY, UNIT_SIZE, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(BodyX, BodyY, UNIT_SIZE3, UNIT_SIZE + UNIT_SIZE4);
g.setColor(Color.black);
g.fillRect(Arm1X, Arm1Y, UNIT_SIZE3, UNIT_SIZE2);
g.setColor(Color.black);
g.fillRect(Arm2X, Arm2Y, UNIT_SIZE3, UNIT_SIZE2);
g.setColor(Color.black);
g.fillRect(Leg1X, Leg1Y, UNIT_SIZE2, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(Leg2X, Leg2Y, UNIT_SIZE2, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(Letter1UnderlineX, Letter1UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter2UnderlineX, Letter2UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter3UnderlineX, Letter3UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter4UnderlineX, Letter4UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter5UnderlineX, Letter5UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter6UnderlineX, Letter6UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter7UnderlineX, Letter7UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter8UnderlineX, Letter8UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
}
我正在创建一个刽子手游戏,我有 body 下来,但是一旦我添加了要显示的 ComboBox none。 我已经看了一个小时了,找不到原因!它应该打印出完整的 body 和字母 a-z。我到处都看过,找不到解决方案。代码很长,因为我真的不知道什么是重要的或不重要的。 (忽略代码中的注释只是帮助我)
public class GamePanel extends JPanel implements ActionListener {
private static final long serialVersionUID = -3919093956447306405L;
static final int SCREEN_WIDTH = 600;
static final int SCREEN_HEIGHT = 600;
static final int UNIT_SIZE = 100;
static final int UNIT_SIZE2 = 19;
static final int UNIT_SIZE3 = 40;
static final int UNIT_SIZE4 = 20;
static final int UNIT_SIZE5 = 60;
// underline ^
static final int UNIT_SIZE6 = (int) 7.5;
// break between ___ fix ^
static final int UNIT_SIZE7 = 0;
// remove the image
static final int GAME_UNITS = (SCREEN_WIDTH*SCREEN_HEIGHT)/UNIT_SIZE;
Random random;
int HeadX = 400;
int HeadY = 100;
int BodyX = 430;
int BodyY = 180;
int Arm1X = 400;
int Arm1Y = 240;
int Arm2X = 460;
int Arm2Y = 240;
int Leg1X = 430;
int Leg1Y = 300;
int Leg2X = 451;
int Leg2Y = 300;
int Letter1UnderlineX = 0+ UNIT_SIZE6;
int Letter1UnderlineY = 535;
int Letter2UnderlineX = 75+ UNIT_SIZE6;
int Letter2UnderlineY = 535;
int Letter3UnderlineX = 150+ UNIT_SIZE6;
int Letter3UnderlineY = 535;
int Letter4UnderlineX = 225+ UNIT_SIZE6;
int Letter4UnderlineY = 535;
int Letter5UnderlineX = 300+ UNIT_SIZE6;
int Letter5UnderlineY = 535;
int Letter6UnderlineX = 375+ UNIT_SIZE6;
int Letter6UnderlineY = 535;
int Letter7UnderlineX = 450+ UNIT_SIZE6;
int Letter7UnderlineY = 535;
int Letter8UnderlineX = 525+ UNIT_SIZE6;
int Letter8UnderlineY = 535;
String a = ("a");
String b = ("b");
String c = ("c");
String d = ("d");
String e = ("e");
String f1 = ("f");
String g1 = ("g");
String h = ("h");
String i = ("i");
String j = ("j");
String k = ("k");
String l = ("l");
String m = ("m");
String n = ("n");
String o = ("o");
String p = ("p");
String q = ("q");
String r = ("r");
String s = ("s");
String t = ("t");
String u = ("u");
String v = ("v");
String w = ("w");
String x = ("x");
String y = ("y");
String z = ("z");
JFrame f;
public static void main(String[] args) {
System.out.println("Welcome to Hang Man!");
Start();
System.out.println("Test");
}
public static void Start(){
Scanner YesNoScanner = new Scanner(System.in);
Scanner Letter = new Scanner(System.in);
String[] letters = new String[100];
String ans = "";
int count = 0;
System.out.println("Would you like to play? (Yes - 1 | No - 2)");
int YesNo = YesNoScanner.nextInt();
if (YesNo == 1) {
System.out.println("Rules: Word MUST be less than or equal to 8 characters \n \t No SPACES in the word or subject \n \t Don't show anyone the word if its your turn for the word ");
System.out.println("You are about to start. \nDon't show anyone the word and subject your word is based off.");
System.out.println("When writing the word only write ONE letter at a time!");
System.out.println("Write 'done' when you are done writing your word.");
System.out.println("\n\nChoose a word between 1-8 characters long\n ( ONE LETTER AT A TIME [press enter after every letter])");
do {
System.out.print("Letter " + (count + 1) + ": " ) ;
ans = Letter.nextLine();
if(!ans.equalsIgnoreCase("done")) {
letters[count] = ans;
count++;
if (count == 8) {
System.out.println("Maximium letters reached");
ans = ("done");
}
}
String one = letters[0];
}while(!ans.equalsIgnoreCase ("done"));
System.out.println("\nYour word is: ");
for(int i = 0; i < count; i++) {
System.out.print(letters[i]);
}
System.out.println(" \nIs this the word you would like? (Yes - 1 | No - 2)");
}else {
System.out.println("You chose to not play. Maybe later :C");
System.exit(0);
}
Scanner YesNoScanner2 = new Scanner(System.in);
int YesNo2 = YesNoScanner2.nextInt();
if (YesNo2 == 1) {
SubjectWrite();
}else {
Start();
}
new GamePanel();
}
public static void SubjectWrite() {
Scanner Subject = new Scanner(System.in);
String ans = "";
System.out.println("Please choose a subject! (1-10 characters long)");
ans = Subject.nextLine();
System.out.println(" \nIs this the Subject you would like? (Yes - 1 | No - 2)");
System.out.println(ans);
Scanner YesNoScanner3 = new Scanner(System.in);
int YesNo3 = YesNoScanner3.nextInt();
if (YesNo3 == 1) {
System.out.println("Are you ready to play? (Yes - 1 | No - 2)");
Scanner YesNoScanner4 = new Scanner(System.in);
int YesNo4 = YesNoScanner4.nextInt();
if(YesNo4 == 1) {
for(int i = 0; i<200;i++) {
System.out.println("\n");
}
}else {
System.exit(0);
}
}else {
System.exit(0);
}
}
//new main method
public void gui() {
f = new JFrame("Title");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
f.pack();
f.setLocationRelativeTo(null);
f.setSize(618, 640);
f.setVisible(true);
String country[]={"India","Aus","U.S.A","England","Newzealand"};
JComboBox cb=new JComboBox(country);
cb.setBounds(50, 50,90,20);
f.add(cb);
f.setLayout(null);
f.setVisible(true);
}
public GamePanel(){
gui();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
draw(g);
}
private void draw(Graphics g) {
// TODO Auto-generated method stub
for(int i=0;i <SCREEN_HEIGHT/UNIT_SIZE;i++) {
g.drawLine(i*UNIT_SIZE, 0, i*UNIT_SIZE, SCREEN_HEIGHT);
g.drawLine(0, i*UNIT_SIZE, SCREEN_WIDTH, i*UNIT_SIZE);
}
int fix1 = 30;
g.setColor(Color.black);
g.setFont(new Font("BiauKai", Font.BOLD, 20));
FontMetrics metrics = getFontMetrics(g.getFont());
g.drawString(a , (SCREEN_WIDTH - metrics.stringWidth(a))-580 + fix1 , g.getFont().getSize());
g.drawString(b , (SCREEN_WIDTH - metrics.stringWidth(b))-560 + fix1 , g.getFont().getSize());
g.drawString(c , (SCREEN_WIDTH - metrics.stringWidth(c))-540 + fix1 , g.getFont().getSize());
g.drawString(d , (SCREEN_WIDTH - metrics.stringWidth(d))-520 + fix1 , g.getFont().getSize());
g.drawString(e , (SCREEN_WIDTH - metrics.stringWidth(e))-500 + fix1 , g.getFont().getSize());
g.drawString(f1 , (SCREEN_WIDTH - metrics.stringWidth(f1))-480 + fix1 , g.getFont().getSize());
g.drawString(g1 , (SCREEN_WIDTH - metrics.stringWidth(g1))-460 + fix1 , g.getFont().getSize());
g.drawString(h , (SCREEN_WIDTH - metrics.stringWidth(h))-440 + fix1 , g.getFont().getSize());
g.drawString(i , (SCREEN_WIDTH - metrics.stringWidth(i))-420 + fix1 , g.getFont().getSize());
g.drawString(j , (SCREEN_WIDTH - metrics.stringWidth(j))-400 + fix1 , g.getFont().getSize());
g.drawString(k , (SCREEN_WIDTH - metrics.stringWidth(k))-380 + fix1 , g.getFont().getSize());
g.drawString(l , (SCREEN_WIDTH - metrics.stringWidth(l))-365 + fix1 , g.getFont().getSize());
g.drawString(m , (SCREEN_WIDTH - metrics.stringWidth(m))-340 + fix1 , g.getFont().getSize());
g.drawString(n , (SCREEN_WIDTH - metrics.stringWidth(n))-320 + fix1 , g.getFont().getSize());
g.drawString(o , (SCREEN_WIDTH - metrics.stringWidth(o))-300 + fix1 , g.getFont().getSize());
g.drawString(p , (SCREEN_WIDTH - metrics.stringWidth(p))-280 + fix1 , g.getFont().getSize());
g.drawString(q , (SCREEN_WIDTH - metrics.stringWidth(q))-260 + fix1 , g.getFont().getSize());
g.drawString(r , (SCREEN_WIDTH - metrics.stringWidth(r))-240 + fix1 , g.getFont().getSize());
g.drawString(s , (SCREEN_WIDTH - metrics.stringWidth(s))-220 + fix1 , g.getFont().getSize());
g.drawString(t , (SCREEN_WIDTH - metrics.stringWidth(t))-200 + fix1 , g.getFont().getSize());
g.drawString(u , (SCREEN_WIDTH - metrics.stringWidth(u))-180 + fix1 , g.getFont().getSize());
g.drawString(v , (SCREEN_WIDTH - metrics.stringWidth(v))-160 + fix1 , g.getFont().getSize());
g.drawString(w , (SCREEN_WIDTH - metrics.stringWidth(w))-140 + fix1 , g.getFont().getSize());
g.drawString(x , (SCREEN_WIDTH - metrics.stringWidth(x))-120 + fix1 , g.getFont().getSize());
g.drawString(y , (SCREEN_WIDTH - metrics.stringWidth(y))-100 + fix1 , g.getFont().getSize());
g.drawString(z , (SCREEN_WIDTH - metrics.stringWidth(z))-80 + fix1 , g.getFont().getSize());
g.drawString(a, (SCREEN_WIDTH - metrics.stringWidth(a))-580 + fix1 , SCREEN_HEIGHT - 560);
//g.drawString(a,40,40);
g.setColor(Color.black);
g.fillOval(HeadX, HeadY, UNIT_SIZE, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(BodyX, BodyY, UNIT_SIZE3, UNIT_SIZE + UNIT_SIZE4);
g.setColor(Color.black);
g.fillRect(Arm1X, Arm1Y, UNIT_SIZE3, UNIT_SIZE2);
g.setColor(Color.black);
g.fillRect(Arm2X, Arm2Y, UNIT_SIZE3, UNIT_SIZE2);
g.setColor(Color.black);
g.fillRect(Leg1X, Leg1Y, UNIT_SIZE2, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(Leg2X, Leg2Y, UNIT_SIZE2, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(Letter1UnderlineX, Letter1UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter2UnderlineX, Letter2UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter3UnderlineX, Letter3UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter4UnderlineX, Letter4UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter5UnderlineX, Letter5UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter6UnderlineX, Letter6UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter7UnderlineX, Letter7UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter8UnderlineX, Letter8UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
- 避免将控制台输入与 GUI 混合使用;
- 你没有给你添加
GamePane
window; - 避免
null
布局
有关更多想法,请参阅 Laying Out Components Within a Container
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.add(new GamePanel());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JTextArea rules = new JTextArea(8, 40);
rules.setWrapStyleWord(true);
rules.setLineWrap(true);
rules.append("Rules: Word MUST be less than or equal to 8 characters\n * No SPACES in the word or subject\n * Don't show anyone the word if its your turn for the word\n");
rules.append("You are about to start. \nDon't show anyone the word and subject your word is based off.");
rules.append("When writing the word only write ONE letter at a time!");
rules.append("Write 'done' when you are done writing your word.");
JOptionPane.showMessageDialog(frame, rules, "The Rules", JOptionPane.PLAIN_MESSAGE);
}
});
}
public class GamePanel extends JPanel implements ActionListener {
private static final long serialVersionUID = -3919093956447306405L;
static final int SCREEN_WIDTH = 600;
static final int SCREEN_HEIGHT = 600;
static final int UNIT_SIZE = 100;
static final int UNIT_SIZE2 = 19;
static final int UNIT_SIZE3 = 40;
static final int UNIT_SIZE4 = 20;
static final int UNIT_SIZE5 = 60;
// underline ^
static final int UNIT_SIZE6 = (int) 7.5;
// break between ___ fix ^
static final int UNIT_SIZE7 = 0;
// remove the image
static final int GAME_UNITS = (SCREEN_WIDTH * SCREEN_HEIGHT) / UNIT_SIZE;
Random random;
int HeadX = 400;
int HeadY = 100;
int BodyX = 430;
int BodyY = 180;
int Arm1X = 400;
int Arm1Y = 240;
int Arm2X = 460;
int Arm2Y = 240;
int Leg1X = 430;
int Leg1Y = 300;
int Leg2X = 451;
int Leg2Y = 300;
int Letter1UnderlineX = 0 + UNIT_SIZE6;
int Letter1UnderlineY = 535;
int Letter2UnderlineX = 75 + UNIT_SIZE6;
int Letter2UnderlineY = 535;
int Letter3UnderlineX = 150 + UNIT_SIZE6;
int Letter3UnderlineY = 535;
int Letter4UnderlineX = 225 + UNIT_SIZE6;
int Letter4UnderlineY = 535;
int Letter5UnderlineX = 300 + UNIT_SIZE6;
int Letter5UnderlineY = 535;
int Letter6UnderlineX = 375 + UNIT_SIZE6;
int Letter6UnderlineY = 535;
int Letter7UnderlineX = 450 + UNIT_SIZE6;
int Letter7UnderlineY = 535;
int Letter8UnderlineX = 525 + UNIT_SIZE6;
int Letter8UnderlineY = 535;
String a = ("a");
String b = ("b");
String c = ("c");
String d = ("d");
String e = ("e");
String f1 = ("f");
String g1 = ("g");
String h = ("h");
String i = ("i");
String j = ("j");
String k = ("k");
String l = ("l");
String m = ("m");
String n = ("n");
String o = ("o");
String p = ("p");
String q = ("q");
String r = ("r");
String s = ("s");
String t = ("t");
String u = ("u");
String v = ("v");
String w = ("w");
String x = ("x");
String y = ("y");
String z = ("z");
//
// JFrame f;
//
// public static void main(String[] args) {
//
// System.out.println("Welcome to Hang Man!");
//
// Start();
//
// System.out.println("Test");
//
// }
//
// public static void Start() {
//
// Scanner YesNoScanner = new Scanner(System.in);
// Scanner Letter = new Scanner(System.in);
// String[] letters = new String[100];
// String ans = "";
// int count = 0;
//
// System.out.println("Would you like to play? (Yes - 1 | No - 2)");
// int YesNo = YesNoScanner.nextInt();
// if (YesNo == 1) {
// System.out.println("Rules: Word MUST be less than or equal to 8 characters \n \t No SPACES in the word or subject \n \t Don't show anyone the word if its your turn for the word ");
// System.out.println("You are about to start. \nDon't show anyone the word and subject your word is based off.");
// System.out.println("When writing the word only write ONE letter at a time!");
// System.out.println("Write 'done' when you are done writing your word.");
//
// System.out.println("\n\nChoose a word between 1-8 characters long\n ( ONE LETTER AT A TIME [press enter after every letter])");
//
// do {
// System.out.print("Letter " + (count + 1) + ": ");
// ans = Letter.nextLine();
// if (!ans.equalsIgnoreCase("done")) {
// letters[count] = ans;
// count++;
// if (count == 8) {
// System.out.println("Maximium letters reached");
// ans = ("done");
//
// }
// }
// String one = letters[0];
// } while (!ans.equalsIgnoreCase("done"));
//
// System.out.println("\nYour word is: ");
// for (int i = 0; i < count; i++) {
// System.out.print(letters[i]);
// }
//
// System.out.println(" \nIs this the word you would like? (Yes - 1 | No - 2)");
//
// } else {
// System.out.println("You chose to not play. Maybe later :C");
// System.exit(0);
// }
//
// Scanner YesNoScanner2 = new Scanner(System.in);
// int YesNo2 = YesNoScanner2.nextInt();
// if (YesNo2 == 1) {
// SubjectWrite();
// } else {
// Start();
// }
//
// new GamePanel();
//
// }
//
// public static void SubjectWrite() {
// Scanner Subject = new Scanner(System.in);
// String ans = "";
//
// System.out.println("Please choose a subject! (1-10 characters long)");
//
// ans = Subject.nextLine();
//
// System.out.println(" \nIs this the Subject you would like? (Yes - 1 | No - 2)");
// System.out.println(ans);
//
// Scanner YesNoScanner3 = new Scanner(System.in);
// int YesNo3 = YesNoScanner3.nextInt();
// if (YesNo3 == 1) {
// System.out.println("Are you ready to play? (Yes - 1 | No - 2)");
// Scanner YesNoScanner4 = new Scanner(System.in);
// int YesNo4 = YesNoScanner4.nextInt();
// if (YesNo4 == 1) {
// for (int i = 0; i < 200; i++) {
// System.out.println("\n");
// }
//
// } else {
// System.exit(0);
// }
//
// } else {
// System.exit(0);
// }
//
// }
// //new main method
// public void gui() {
// f = new JFrame("Title");
// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// f.setResizable(false);
// f.pack();
// f.setLocationRelativeTo(null);
// f.setSize(618, 640);
// f.setVisible(true);
// f.add(cb);
// f.setLayout(null);
// f.setVisible(true);
// }
public GamePanel() {
String country[] = {"India", "Aus", "U.S.A", "England", "Newzealand"};
JComboBox cb = new JComboBox(country);
cb.setBounds(50, 50, 90, 20);
add(cb);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(640, 640);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
draw(g);
}
private void draw(Graphics g) {
// TODO Auto-generated method stub
for (int i = 0; i < SCREEN_HEIGHT / UNIT_SIZE; i++) {
g.drawLine(i * UNIT_SIZE, 0, i * UNIT_SIZE, SCREEN_HEIGHT);
g.drawLine(0, i * UNIT_SIZE, SCREEN_WIDTH, i * UNIT_SIZE);
}
int fix1 = 30;
g.setColor(Color.black);
g.setFont(new Font("BiauKai", Font.BOLD, 20));
FontMetrics metrics = getFontMetrics(g.getFont());
g.drawString(a, (SCREEN_WIDTH - metrics.stringWidth(a)) - 580 + fix1, g.getFont().getSize());
g.drawString(b, (SCREEN_WIDTH - metrics.stringWidth(b)) - 560 + fix1, g.getFont().getSize());
g.drawString(c, (SCREEN_WIDTH - metrics.stringWidth(c)) - 540 + fix1, g.getFont().getSize());
g.drawString(d, (SCREEN_WIDTH - metrics.stringWidth(d)) - 520 + fix1, g.getFont().getSize());
g.drawString(e, (SCREEN_WIDTH - metrics.stringWidth(e)) - 500 + fix1, g.getFont().getSize());
g.drawString(f1, (SCREEN_WIDTH - metrics.stringWidth(f1)) - 480 + fix1, g.getFont().getSize());
g.drawString(g1, (SCREEN_WIDTH - metrics.stringWidth(g1)) - 460 + fix1, g.getFont().getSize());
g.drawString(h, (SCREEN_WIDTH - metrics.stringWidth(h)) - 440 + fix1, g.getFont().getSize());
g.drawString(i, (SCREEN_WIDTH - metrics.stringWidth(i)) - 420 + fix1, g.getFont().getSize());
g.drawString(j, (SCREEN_WIDTH - metrics.stringWidth(j)) - 400 + fix1, g.getFont().getSize());
g.drawString(k, (SCREEN_WIDTH - metrics.stringWidth(k)) - 380 + fix1, g.getFont().getSize());
g.drawString(l, (SCREEN_WIDTH - metrics.stringWidth(l)) - 365 + fix1, g.getFont().getSize());
g.drawString(m, (SCREEN_WIDTH - metrics.stringWidth(m)) - 340 + fix1, g.getFont().getSize());
g.drawString(n, (SCREEN_WIDTH - metrics.stringWidth(n)) - 320 + fix1, g.getFont().getSize());
g.drawString(o, (SCREEN_WIDTH - metrics.stringWidth(o)) - 300 + fix1, g.getFont().getSize());
g.drawString(p, (SCREEN_WIDTH - metrics.stringWidth(p)) - 280 + fix1, g.getFont().getSize());
g.drawString(q, (SCREEN_WIDTH - metrics.stringWidth(q)) - 260 + fix1, g.getFont().getSize());
g.drawString(r, (SCREEN_WIDTH - metrics.stringWidth(r)) - 240 + fix1, g.getFont().getSize());
g.drawString(s, (SCREEN_WIDTH - metrics.stringWidth(s)) - 220 + fix1, g.getFont().getSize());
g.drawString(t, (SCREEN_WIDTH - metrics.stringWidth(t)) - 200 + fix1, g.getFont().getSize());
g.drawString(u, (SCREEN_WIDTH - metrics.stringWidth(u)) - 180 + fix1, g.getFont().getSize());
g.drawString(v, (SCREEN_WIDTH - metrics.stringWidth(v)) - 160 + fix1, g.getFont().getSize());
g.drawString(w, (SCREEN_WIDTH - metrics.stringWidth(w)) - 140 + fix1, g.getFont().getSize());
g.drawString(x, (SCREEN_WIDTH - metrics.stringWidth(x)) - 120 + fix1, g.getFont().getSize());
g.drawString(y, (SCREEN_WIDTH - metrics.stringWidth(y)) - 100 + fix1, g.getFont().getSize());
g.drawString(z, (SCREEN_WIDTH - metrics.stringWidth(z)) - 80 + fix1, g.getFont().getSize());
g.drawString(a, (SCREEN_WIDTH - metrics.stringWidth(a)) - 580 + fix1, SCREEN_HEIGHT - 560);
//g.drawString(a,40,40);
g.setColor(Color.black);
g.fillOval(HeadX, HeadY, UNIT_SIZE, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(BodyX, BodyY, UNIT_SIZE3, UNIT_SIZE + UNIT_SIZE4);
g.setColor(Color.black);
g.fillRect(Arm1X, Arm1Y, UNIT_SIZE3, UNIT_SIZE2);
g.setColor(Color.black);
g.fillRect(Arm2X, Arm2Y, UNIT_SIZE3, UNIT_SIZE2);
g.setColor(Color.black);
g.fillRect(Leg1X, Leg1Y, UNIT_SIZE2, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(Leg2X, Leg2Y, UNIT_SIZE2, UNIT_SIZE);
g.setColor(Color.black);
g.fillRect(Letter1UnderlineX, Letter1UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter2UnderlineX, Letter2UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter3UnderlineX, Letter3UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter4UnderlineX, Letter4UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter5UnderlineX, Letter5UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter6UnderlineX, Letter6UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter7UnderlineX, Letter7UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
g.setColor(Color.black);
g.fillRect(Letter8UnderlineX, Letter8UnderlineY, UNIT_SIZE5, UNIT_SIZE3);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
}