0

Okay, my game works fine. I recently added new difficulties. Those work as well. Now I'm banging my head on the wall to find out how to connect it all together. Now the game wont be operated by the console when published, but this is testing so I'm making sure I can pull this off.

Here's the GUI of one of the difficulties (No game logic included):

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g.setColor(Color.DARK_GRAY);
    Rectangle2D rect3 = new Rectangle2D.Double(395, 0, 10, 800);
    g2.fill(rect3);
    g.setColor(Color.CYAN);
    Ellipse2D circle = new Ellipse2D.Double(ballX, ballY, ballrad, ballrad);
    g2.fill(circle);
    g.setColor(Color.LIGHT_GRAY);
    Rectangle2D rect = new Rectangle2D.Double(rectX, rectY, 20, 200);
    g2.fill(rect);
    g.setColor(Color.LIGHT_GRAY);
    Rectangle2D rect2 = new Rectangle2D.Double(rect2X, rect2Y, 20, 200);
    g2.fill(rect2);
    g.setColor(Color.GRAY);
    Font font = new Font("Sans-Serif", Font.PLAIN, 32);
    g2.setFont(font);
    g2.drawString(String.valueOf(lPlayerScore), 340, 100);
    g.setColor(Color.GRAY);
    Font font2 = new Font("Sans-Serif", Font.PLAIN, 32);
    g2.setFont(font2);
    g2.drawString(String.valueOf(rPlayerScore), 435, 100);
    dest.start();
}

If I connected this class to a basic window class, it would work perfectly. A basic window class meaning just a window that pops up waiting for something to feed in.

Now, I am only going to present the window-scanner-opening logic with 1 mode so you can see what I mean:

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JFrame;

import java.awt.*;

import javax.swing.*;

import java.awt.Canvas;

import javax.swing.JFrame;

import java.applet.*;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Color;

import javax.swing.JPanel;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Ellipse2D;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.util.Formatter;
import java.util.Scanner;

public class screen extends JFrame{
    private static final long serialVersionUID = 1L;
    public static void main(String args[])
    {
        String askeasy = "Easy";
        Scanner scan = new Scanner(System.in);
        String chosenmode = scan.nextLine();

        if (chosenmode == askeasy)
        {
            parts parts = new parts();
            JFrame frame = new JFrame();
            frame.add(parts);
            frame.setVisible(true);
            frame.setSize(800, 800);
            frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
            frame.setTitle("Pong");
            frame.addKeyListener(parts);
        }
    }
}

Whenever I run this more advanced screen class, I get nothing.

Any type of feedback would be appreciated.

CA1K
  • 35
  • 8
  • small mistake: `(chosenmode == askeasy)` - it's wrong code. You must use `askeasy.equals(chosenmode)`. Can you add your parts class code? – Andrey Pushin Dec 20 '14 at 10:28

1 Answers1

0

You must change

(chosenmode == askeasy)

to

askeasy.equals(chosenmode)

For more information: How do I compare strings in Java?

Community
  • 1
  • 1