Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Selection does not maintain a main type error
Selection does not maintain a main type error [message #665797] Sat, 16 April 2011 02:44 Go to next message
No real name is currently offline No real nameFriend
Messages: 1
Registered: April 2011
Junior Member
Hello, I'm completely new to eclipse and Java. I'm attempting to run a java program I wrote but I keep receiving A "Selection does not maintain a main type" error, even though It appears to. I've looked up the error on other forums but I'm still confused.

I'm attempting to make an editable ascii animation.
I'm running it as a java application. I just downloaded eclipse today, maybe I don't have something set up correctly but I walked though the "Preparing eclipse" in the tutorials.

I'm also not sure if my java code is correct or not, I believe files/classes which are in the same project don't need to be explicitly imported to use each other. Any ways The following are my three files I'm using.

InheritanceAnimation
// InheritanceAnimation
// include/import MFrame?

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.Jbutton;


public class InheritanceAnimation{
	public static void main (String[] args) {
		// create MFrame
		MFrame MFrameArea = new MFrame(20,10);
		MFrame.setDefaultCloseOperation("JFrame.EXIT_ON_CLOSE");
		MFrame.setSize(350,100);//Set
		MFrame.setVisible(true);//display frame
	
		// Create radio buttons
		StepBack = new JButton("StepBack");
		Pause = new JButton("Pause");
		Play = new JButton("Forward");
		StepForward = new JButton("StepBack");
		SaveFrame = new JButton("Save");
	
		// Add buttons to JFrame
		add(StepBack);
		add(Pause);
		add(Play);
		add(StepForward);
		add(SaveFrame);
	
	
		// Register Events for JButtons, thanks to http://stackoverflow.com/questions/1346978/java-using-an-actionlistener-to-call-a-function-in-another-class-on-an-object-fr for help.
		StepBack.addActionListener(new ActionListener() { @Override public void actionPerforemd(ActionEvent e){MFrameArea.StepBack(MFrameArea.ReturnCurrentFrame()));}});
		Pause.addItemListener(new ActionListener() { @Override public void actionPerforemd(ActionEvent e){MFrameArea.Pause());});
		Play.addItemListener(new ActionListener() { @Override public void actionPerforemd(ActionEvent e){MFrameArea.Play(MFrameArea.ReturnCurrentFrame(),1000));});
		StepForward.addItemListener(new ActionListener() { @Override public void actionPerforemd(ActionEvent e){MFrameArea.StepForward(MFrameArea.ReturnCurrentFrame()));});
		SaveFrame.addItemListener(new ActionListener() { @Override public void actionPerforemd(ActionEvent e){MFrameArea.SaveFrame(MFrameArea.ReturnCurrentFrame()));});
	}

}


MFrame
Quote:

// MFrame Class
// include/import implementation?

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JTextFrame;

public class MFrame extends JTextArea implements Implementation
{
private JTextField TextField;
private int I =0;
private string[] Frames= new string[10];
Frames = {"*"," *"," *"," *","\n*","\n *","\n *","\n *"," Edit Me","The End"};
private int Pause = 0;


// Constructor
public MFrame(Rows,Cols){
TextField = new JTextField(Rows, Cols);
TextArea.setTabSize(1);//Makes Tab Predictable
TextArea.setLineWrap(o); //No wrapping

//Register Event handlers
TextFieldHandler Handler = new TextFieldHandler(Rows,Cols);
TextArea.addActionListener(Handler);

add(TextField); //AddTextField to JFrame
}

@OverRide
private void Load(i){
I=i;
TextField.setText(Frames[I]);
}
@OverRide
Public void Save(int i);
Pause = 1; // Stop Play function if its Running
I=i;
Frames[I] = TextField.getText();
}
@OverRide
public void StepForward(int i){
Pause = 1;// Stop Play function if its running
pause = 0;
I = i++;
if(I>9){I=9;}
Load(I);
}
@OverRide
public void StepBackward(int i){
Pause = 1; // Stop Play function if its running
Pause = 0;
I = i--;
if(I<0){I=0;}
Load(I);
}
@OverRide
public void Play(int i,int Rate){
Pause = 0;
long TimeThen= System.currentTimeMillis();
long TimeNow;
for(I=i;I<10;I++){
//Delays the Load function call
while(TimeNow -TimeThen < Rate && Pause == 0){
TimeNow = System.currentTimeMillis();
}
if( pause == 0){
Load(I);
}
}
@OverRide
public void PauseMFrame(){
Pause = 1;
}
@OverRide
public int ReturnCurrentFrame(){
return I;
}

}
//Private inner class for event handling
private class TextFieldHandler implements ActionListener
public void Limits(LRows,LCols){ // Problem: Assumes each line is the same length, will fix later.
int Rows = TextArea.getLineCount();
int Cols =TextArea.getText.split("\n")[Rows-1].length();
if (Rows =>LRows || Cols => LCols){
replaceRange("",Rows*Cols,Rows*Cols+1);
JOptionPane.showMessageDialog(null,"You've Entered either too many characters or too many Rows");
}
}




Implementation
Quote:


public interface Implementation{
public MFrame(int,int);
Private void Load(int);
Public void Save(int );
Public void StepForward(int);
Public void StepBackward(int);
public void Play(int,int);
public void PauseFrame(int);
Public int ReturnCurrentFrame();
}

[Updated on: Sat, 16 April 2011 02:52]

Report message to a moderator

Re: Selection does not maintain a main type error [message #666222 is a reply to message #665797] Tue, 19 April 2011 13:54 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
Are there any compilation error reported (see the Errors view)?
What are you selecting when trying to run the program? The class
InheritanceAnimation does have a main() method with the correct
signature, but maybe you've selected something else to run...

Eric


On 4/15/11 10:44 PM, casper3912@ymail.com wrote:
> Hello, I'm completely new to eclipse and Java. I'm attempting to run a
> java program I wrote but I keep receiving A "Selection does not maintain
> a main type" error, even though It appears to. I've looked up the error
> on other forums but I'm still confused.
> I'm attempting to make an editable ascii animation. I'm running it as a
> java application. I just downloaded eclipse today, maybe I don't have
> something set up correctly but I walked though the "Preparing eclipse"
> in the tutorials.
> I'm also not sure if my java code is correct or not, I believe
> files/classes which are in the same project don't need to be explicitly
> imported to use each other. Any ways The following are my three files
> I'm using.
> InheritanceAnimation
> // InheritanceAnimation
> // include/import MFrame?
>
> import javax.swing.JFrame;
> import java.awt.event.ItemListener;
> import java.awt.event.ItemEvent;
> import javax.swing.JRadioButton;
> import javax.swing.ButtonGroup;
>
> public class InheritanceAnimation{
> public static void main (String[] args) {
> // create MFrame
> MFrame MFrameArea = new MFrame(20,10);
> MFrame.setDefaultCloseOperation("JFrame.EXIT_ON_CLOSE");
> MFrame.setSize(350,100);//Set
> MFrame.setVisible(true);//display frame
>
> // Create radio buttons
> StepBack = new JButton("StepBack");
> Pause = new JButton("Pause");
> Play = new JButton("Forward");
> StepForward = new JButton("StepBack");
> SaveFrame = new JButton("Save");
>
> // Add buttons to JFrame
> add(StepBack);
> add(Pause);
> add(Play);
> add(StepForward);
> add(SaveFrame);
>
>
> // Register Events for JButtons, thanks to
> http://stackoverflow.com/questions/1346978/java-using-an-act ionlistener-to-call-a-function-in-another-class-on-an-object -fr
> for help.
> StepBack.addActionListener(new ActionListener() { @Override public void
> actionPerforemd(ActionEvent
> e){MFrame.StepBack(MFrame.ReturnCurrentFrame()));}});
> Pause.addItemListener(new ActionListener() { @Override public void
> actionPerforemd(ActionEvent e){MFrame.Pause());});
> Play.addItemListener(new ActionListener() { @Override public void
> actionPerforemd(ActionEvent
> e){MFrame.Play(MFrame.ReturnCurrentFrame(),1000));});
> StepForward.addItemListener(new ActionListener() { @Override public void
> actionPerforemd(ActionEvent
> e){MFrame.StepForward(MFrame.ReturnCurrentFrame()));});
> SaveFrame.addItemListener(new ActionListener() { @Override public void
> actionPerforemd(ActionEvent
> e){MFrame.SaveFrame(MFrame.ReturnCurrentFrame()));});
> }
>
> }
>
>
> MFrame
> Quote:
>> // MFrame Class
>> // include/import implementation?
>>
>> import java.awt.event.ActionListener;
>> import java.awt.event.ActionEvent;
>> import javax.swing.JFrame;
>> import javax.swing.JTextFrame;
>>
>> public class MFrame extends JTextArea implements Implementation
>> {
>> private JTextField TextField;
>> private int I =0;
>> private string[] Frames= new string[10];
>> Frames = {"*"," *"," *"," *","\n*","\n *","\n *","\n *"," Edit
>> Me","The End"};
>> private int Pause = 0;
>>
>>
>> // Constructor
>> public MFrame(Rows,Cols){
>> TextField = new JTextField(Rows, Cols);
>> TextArea.setTabSize(1);//Makes Tab Predictable
>> TextArea.setLineWrap(o); //No wrapping
>>
>> //Register Event handlers
>> TextFieldHandler Handler = new TextFieldHandler(Rows,Cols);
>> TextArea.addActionListener(Handler);
>> add(TextField); //AddTextField to JFrame
>> }
>>
>> @OverRide
>> private void Load(i){
>> I=i;
>> TextField.setText(Frames[I]);
>> }
>> @OverRide
>> Public void Save(int i);
>> Pause = 1; // Stop Play function if its Running
>> I=i;
>> Frames[I] = TextField.getText();
>> }
>> @OverRide
>> public void StepForward(int i){
>> Pause = 1;// Stop Play function if its running
>> pause = 0;
>> I = i++;
>> if(I>9){I=9;}
>> Load(I);
>> }
>> @OverRide
>> public void StepBackward(int i){
>> Pause = 1; // Stop Play function if its running
>> Pause = 0;
>> I = i--;
>> if(I<0){I=0;}
>> Load(I);
>> }
>> @OverRide
>> public void Play(int i,int Rate){
>> Pause = 0;
>> long TimeThen= System.currentTimeMillis();
>> long TimeNow;
>> for(I=i;I<10;I++){
>> //Delays the Load function call
>> while(TimeNow -TimeThen < Rate && Pause == 0){
>> TimeNow = System.currentTimeMillis();
>> }
>> if( pause == 0){
>> Load(I);
>> }
>> }
>> @OverRide
>> public void PauseMFrame(){
>> Pause = 1;
>> }
>> @OverRide
>> public int ReturnCurrentFrame(){
>> return I;
>> }
>>
>> }
>> //Private inner class for event handling
>> private class TextFieldHandler implements ActionListener
>> public void Limits(LRows,LCols){ // Problem: Assumes each line is the
>> same length, will fix later.
>> int Rows = TextArea.getLineCount();
>> int Cols =TextArea.getText.split("\n")[Rows-1].length();
>> if (Rows =>LRows || Cols => LCols){
>> replaceRange("",Rows*Cols,Rows*Cols+1);
>> JOptionPane.showMessageDialog(null,"You've Entered either too many
>> characters or too many Rows");
>> }
>> }
>
>
> Implementation
> Quote:
>> public interface Implementation{
>> public MFrame(int,int);
>> Private void Load(int);
>> Public void Save(int );
>> Public void StepForward(int);
>> Public void StepBackward(int);
>> public void Play(int,int);
>> public void PauseFrame(int);
>> Public int ReturnCurrentFrame();
>> }
>
Previous Topic:Define a New Server in Eclipse from command Line
Next Topic:Best way to create multiple relate programs
Goto Forum:
  


Current Time: Wed Apr 24 13:41:33 GMT 2024

Powered by FUDForum. Page generated in 0.07957 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top