#weird JLabel graphics bug
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
well, u could invest time into making it easier to help u
there's a lot u could do
u could share snippets directly here in discord, removing one access barrier. u could explain ur code. u could share screenshot. u could explain the problem in more detail
the more u invest, the likelier someone will help
maybe it's just a feeling, but it's always u who has trouble with getting responses bc of too few details, or am i remembering wrong?
ii can only repeat what i just posted
before u did that, i will keep clicking away ur thread each time u bump it
i guess same happens for other helpers as well
right now ur question is in a Format that i know I would need prob 15 mins of reading until im helpful. don't have that time. ill wait until u prepared it so that it's just 5mins. with the simple steps i mentioned above that only cost u 10 minutes
if ur too lazy to do that, I'm too lazy to help u. its not the first time im telling u that
i gave u a list of things to provide
right now ur code is in pastebin. that's good, but better would be if it's in discord. well formatted text with syntax highlighting
then i dont have to click on a link first
sounds stupid, but many people don't click on links
at least not before they decided to help
that's why i said snippets
u should have the core part of the code here
and the full code on pastebin for reference
and then explain ur code. tell us what's going on, provide context. guide us
Also shows Screenshots
and explain the issue based on the Screenshots
all that makes ur question more accessible and people are more likely to say "ah yeah, i think i can help with that" instead of "oof, i dont even know what it's about, i guess ill help someone else"
this decision is made within a few seconds after reading ur post
Detected code, here are some useful tools:
void startMainMenu() {
this .setTitle("Zushee Game");
this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this .setSize(600, 400);
this .setResizable(false);
this .setVisible(true);
menu = new JPanel();
menu.setLayout(null );
menu.setBounds(0, 0, 600, 400);
menu.setBackground(Color.CYAN);
mainText = new JLabel("THE ZUSHEE GAME!");
mainText.setFont(new Font("minecraft", Font.BOLD, 50));
mainText.setHorizontalAlignment(JLabel.CENTER);
mainText.setVerticalAlignment(JLabel.TOP);
mainText.setLayout(null );
mainText.setBounds(45, 10, 500, 60);
startButton = new JButton();
startButton.setLayout(null );
startButton.setBounds(150, 120, 300, 100);
startButton.setHorizontalAlignment(JLabel.CENTER);
startButton.setVerticalAlignment(JLabel.TOP);
startButton.setFocusable(false);
startButton.setText("Play");
startButton.setFont(new Font("minecraft", Font.BOLD, 70));
startButton.setOpaque(true);
quitButton = new JButton();
quitButton.setLayout(null );
quitButton.setBounds(150, 245, 300, 100);
quitButton.setHorizontalAlignment(JLabel.CENTER);
quitButton.setVerticalAlignment(JLabel.BOTTOM);
quitButton.setFocusable(false);
quitButton.setText("Quit");
quitButton.setFont(new Font("minecraft", Font.BOLD, 70));
quitButton.setOpaque(true);
menu.add(mainText);
menu.add(startButton);
menu.add(quitButton);
this .add(menu);
this .repaint();
startButton.addActionListener(e -> startGame());
quitButton.addActionListener(e -> {
this .dispose();
System.exit(69);
}
);
}
Detected code, here are some useful tools:
void startGame() {
inOnMenu = false;
System.out.println("twerks");
menu.setVisible(false);
this .remove(menu);
game = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super .paintComponent(g);
Graphics graphics = g.create();
graphics.setColor(Color.CYAN);
//DRAW SQUARES
if (!hasDrawn) {
for (int i = 0; i < SCREEN_HEIGHT / BLOCK_SIZE; i++) {
for (int j = 0; j < SCREEN_WIDTH / BLOCK_SIZE; j++) {
if (RNG.generateRandomRange(0, 10) == 5) {
SQUARES_IN_WINDOW[i] [j] = true;
graphics.fillRect(j * 20, i * 20, 20, 20);
}
}
}
}
graphics.dispose();
hasDrawn = true;
}
};
game.setLayout(null );
character = new JLabel() {
@Override
protected void paintComponent(Graphics g) {
//super.paintComponent(g);
g.setColor(Color.RED);
g.fillRect(0, 0, getWidth(), getHeight());
System.out.println("painted!");
}
};
character.setPreferredSize(new Dimension(20, 20));
game.setBackground(Color.BLACK);
character.setVisible(true);
this .addKeyListener(new Main());
game.add(character);
this .add(game);
character.setBounds(playerRow, playerCol, 20, 20);
}
Detected code, here are some useful tools:
public void keyPressed(KeyEvent e) {
if (!isKeyPressed) {
isKeyPressed = true;
int keyCode = e.getKeyCode();
System.out.println("y=" + playerRow);
System.out.println("x=" + playerCol);
switch (keyCode) {
case KeyEvent.VK_W -> playerRow--;
case KeyEvent.VK_A -> playerCol--;
case KeyEvent.VK_S -> {
playerRow++;
spawnsussybaka();
}
case KeyEvent.VK_D -> playerCol++;
}
character.setBounds(playerCol * 20, playerRow * 20, 20, 20);
if ((playerRow < 0 || playerCol < 0 || playerCol > 29 || playerRow > 18) || SQUARES_IN_WINDOW[playerRow] [playerCol] ) {
System.exit(69);
}
}
}
Detected code, here are some useful tools:
public void spawnsussybaka() {
JLabel label = new JLabel() {
@Override
protected void paintComponent(Graphics g) {
super .paintComponent(g);
Graphics graphics = g.create();
graphics.setColor(RNG.getRandomColor());
graphics.setFont(new Font(null , Font.PLAIN, 2));
graphics.fillOval(0, 0, getWidth(), getHeight());
graphics.setColor(RNG.getRandomColor());
graphics.fillOval(3, 3, 14, 14);
graphics.setColor(RNG.getRandomColor());
graphics.fillOval(6, 6, 8, 8);
graphics.dispose();
}
};
int x = RNG.generateRandomRange(0, 30) * 20;
int y = RNG.generateRandomRange(0, 20) * 20;
System.out.println(x + "####" + y);
label.setLayout(null );
label.setForeground(Color.blue);
label.setPreferredSize(new Dimension(20, 20));
label.setBounds(x, y, 20, 20);
game.add(label);
label.repaint();
if (sussybakastotal < 3) sussybakastotal++;
}
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍
u could explain ur code. u could share screenshot. u could explain the problem in more detail
before u did that, i will keep clicking away ur thread each time u bump it
u could explain ur code.
u posted like 1k lines of code and all u have to say to explain that is one sentence?
im kinda tired of constantly having to pull everything out of ur nose
sorry, maybe someone else has the time and mood
as said, im out. someone else can help u