I have a string of text "Highscore: " and I want this to show up at the bottom of my JFrame. When I try to increase the y the text shows up to about 100 and then if I want to increase it anymore it disappears? I want it past 100 though...
Here is my code:
package Main;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Game {
public static void main(String[] args) {
final JFrame frame = new JFrame("Tennis Game");
frame.setSize(300,400);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Graphics add
Menu graphics = new Menu();
frame.add(graphics);
graphics.setBounds(0, 0, 300, 100);
frame.setLayout(null);
//Buttons
//Play button
final JButton b = new JButton("Play");
b.setFocusPainted(false);
b.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 20));
b.setBounds(110,100,80,40);
b.setForeground(Color.BLACK);
b.addMouseListener(new java.awt.event.MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
b.setForeground(Color.RED);
b.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent evt) {
b.setForeground(Color.BLACK);
}
public void mouseClicked(MouseEvent evt){
}
});
//Exit button
final JButton b2 = new JButton("Exit");
b2.setFocusPainted(false);
b2.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 20));
b2.setBounds(110, 180, 80, 40);
b2.setForeground(Color.BLACK);
b2.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent evt) {
System.exit(0);
}
});
b2.addMouseListener(new java.awt.event.MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
b2.setForeground(Color.RED);
b2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent evt) {
b2.setForeground(Color.BLACK);
}
});
//Help Button
final JButton b3 = new JButton("Help");
b3.setFocusPainted(false);
b3.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 20));
b3.setBounds(110, 140, 80, 40);
b3.setForeground(Color.BLACK);
b3.addMouseListener(new java.awt.event.MouseAdapter(){
public void mouseEntered(MouseEvent evt) {
b3.setForeground(Color.RED);
b3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent evt) {
b3.setForeground(Color.BLACK);
}
public void mouseClicked(MouseEvent evt){
}
});
frame.add(b);
frame.add(b2);
frame.add(b3);
}
}
Also:
package Main;
import java.awt.Color;
import java.awt.Font;
import java.awt.*;
import javax.swing.*;
public class Menu extends JPanel {
int highscore = 0;
public void paintComponent(Graphics g){
super.paintComponent(g);
g.setFont(new Font("Arial", Font.BOLD, 30));
g.setColor(Color.BLACK);
g.drawString("TENNIS GAME", 40, 60);
g.setFont(new Font("Arial", Font.BOLD, 18));
g.setColor(Color.BLACK);
g.drawString("Made by Jared Butterfield", 36, 82);
//TEXT HERE
//TEXT HERE
//TEXT HERE
g.setFont(new Font("Arial", Font.BOLD, 18));
g.setColor(Color.BLACK);
g.drawString("Highscore: "+ highscore, 0, 150);
}
}
I tried to add comments where the highscore text was for help.
Aucun commentaire:
Enregistrer un commentaire