Need some help
I have 2 java programs
TicTacToe.java(2 player mode)
TicTacToeAI.java(AI mode)
I plan to create a java menu bar for the 2 programs
I have this:
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class FinalProject extends JFrame implements ActionListener { public FinalProject() { MenuBar menuBar = new MenuBar(); setMenuBar(menuBar); Menu menuFile = new Menu("Game", true); menuBar.add(menuFile); MenuItem menuTTT = new MenuItem("Versus Mode"); menuFile.add(menuTTT); MenuItem menuTTTAI = new MenuItem("Versus AI"); menuFile.add(menuTTTAI); Menu menuAbout = new Menu("About", true); menuBar.add(menuAbout); MenuItem menuAboutTicTacToe = new MenuItem("About TicTacToe"); menuAbout.add(menuAboutTicTacToe); menuTTT.addActionListener(this); menuTTTAI.addActionListener(this); menuAboutTicTacToe.addActionListener(this); menuTTT.setActionCommand("Versus Mode"); menuTTTAI.setActionCommand("Versus AI"); menuAboutTicTacToe.setActionCommand("About"); } public void createAndShow() { setDefaultCloseOperation(EXIT_ON_CLOSE); setPreferredSize(new Dimension(100, 80)); setLocation((1000/2), (400/2)); pack(); setVisible(true); } public void actionPerformed(ActionEvent e) { String arg = e.getActionCommand(); if (arg == "Versus Mode") { } if (arg == "Versus AI") { } if (arg == "About") { String message = "Elson's TicTacToe\nComputer Programming II\nCopyright 2011\nAll rights reserved"; JOptionPane.showMessageDialog(null,message, "The Programmer", JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] args) { FinalProject frame = new FinalProject(); frame.createAndShow(); } }
how can I call the 2 programs and insert here:
public void actionPerformed(ActionEvent e) { String arg = e.getActionCommand(); if (arg == "Versus Mode") { } if (arg == "Versus AI") { }