Hello,
I have a simple GUI but when i put another Jframe in an action listener it squishes the main page in with the new Jframe, i know this is probably basic but my text book yeilds no result, here is my code. Maybe i am going about the process in the wrong way. But i want my programm to be able to access one frame from a button push in another frame, if you run the code you will hopefully see what i mean
Is there something in particular i should read up on?
Any help would be sweet, thanks (class is Interface)
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Interface extends JFrame
{
public static final int WIDTH = 600;
public static final int HEIGHT = 500;
int i = 0;
private JButton newSongB, exitB, deleteSongB, playlistB, searchB;
private NewSongButtonHandler nsHandler;
private DeleteSongButtonHandler dsHandler;
private PlaylistButtonHandler plHandler;
private SearchButtonHandler sbHandler;
private ExitButtonHandler ebHandler;
public JLabel nameL, artistL, fileSizeL, durationL;
public JTextField nameTF, artistTF, fileSizeTF, durationTF;
public JButton menuB,enterSongB;
public MainMenuHandler mmHandler;
public EnterSongDataHandler sdHandler;
//private void run()
//{
//This method should control the flow of the program
//and have all code for accessing the playlists
//and song database
public Interface ()
{
setTitle("Mp3 database: Please select Function");
newSongB = new JButton("Enter New Song");
nsHandler = new NewSongButtonHandler();
newSongB.addActionListener(nsHandler);
deleteSongB = new JButton("Delete Song");
dsHandler = new DeleteSongButtonHandler();
deleteSongB.addActionListener(dsHandler);
playlistB = new JButton("Playlist");
plHandler = new PlaylistButtonHandler();
playlistB.addActionListener(plHandler);
searchB = new JButton("Search Database");
sbHandler = new SearchButtonHandler();
searchB.addActionListener(sbHandler);
exitB = new JButton("Exit");
ebHandler = new ExitButtonHandler();
exitB.addActionListener(ebHandler);
Container pane = getContentPane();
pane.setLayout(new GridLayout(5,0));
pane.add(newSongB);
pane.add(deleteSongB);
pane.add(playlistB);
pane.add(searchB);
pane.add(exitB);
setSize(WIDTH,HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class NewSongButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//JFrame newFrame = new JFrame("This frame popped up");
//newFrame.setSize(100,100);
//newFrame.setVisible(true);
setTitle("Enter Song Info");
nameTF = new JTextField(10);
artistTF = new JTextField(10);
fileSizeTF = new JTextField(10);
durationTF = new JTextField(10);
nameL = new JLabel("Enter Song Name: ",SwingConstants.CENTER);
artistL = new JLabel("Enter Artist Name: ",SwingConstants.CENTER);
fileSizeL = new JLabel("Enter File Size (in Kbytes)",SwingConstants.CENTER);
durationL = new JLabel("Enter song Duration (in Seconds)",SwingConstants.CENTER);
enterSongB = new JButton("Add Song");
sdHandler = new EnterSongDataHandler();
enterSongB.addActionListener(sdHandler);
menuB = new JButton("Main Menu");
mmHandler = new MainMenuHandler();
menuB.addActionListener(mmHandler);
Container pane = getContentPane();
pane.setLayout(new GridLayout(5,2));
pane.add(nameL);
pane.add(nameTF);
pane.add(artistL);
pane.add(artistTF);
pane.add(fileSizeL);
pane.add(fileSizeTF);
pane.add(durationL);
pane.add(durationTF);
pane.add(enterSongB);
pane.add(menuB);
setSize(WIDTH,HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
private class DeleteSongButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
private class PlaylistButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
private class SearchButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
private class ExitButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
private class EnterSongDataHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
private class MainMenuHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
//}
public static void main(String[] args){
Interface intFace = new Interface();
//intFace.run();
}
}