• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DrawingHouse program

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really need help my grade depends on this!!
So in my programming class we are suppose to create a picture of a house. ive been having a problem with my java compiler(in Eclipse), it keeps returning "Selection does not contain a main type".

Heres the program can some one tell me what to
import javax.Swing.*;
import java.awt.*;



public class House extends JFrame {

public House()
{
super();
Container contentPane = getContentPane();

setSize(800,600);

setTitle("My House");

contentPane.setbackground(Color.blue);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void paint(Graphics g)
{

Super.paint(g);


g.setColor(Color.green);
g.fillRect(0,450,800, 450);

g.setColor(new Color(222,184,135));
g.fillRect(275,250,250,250);

g.setColor(new Color(139,69,19) );
int[] x = {250,400,550};
int[] y = {270,100,270};
g.drawPolygon(x,y,3);
g.fillPolygon(x,y,3);

g.setColor(new Color(139,69,19));
g.fillRect(370,400,60,100);
g.setColor(new Color(0,0,0));
g.fillOval(380,440,10,10);

g.setColor(new Color(255,250,205));
g.fillRect(315,300,50,50);
g.fillRect(435,300,50,50);
g.setCOlor(new Color(0,0,0));
g.drawLine(315,325,265,325);
g.drawLine(340,300,340,350);
g.drawLine(435,325,485,325);
g.drawLine(460,300,460,350);

g.setColor(new Color (139,69,19);
g.fillOval(380,505,45,25);
g.fillOval(360,535,45,25);
g.fillOval(335,560,45,25);

g.fillOval(50,50,130,80);
g.fillOval(120,50,110,80);

g.setColor(Color.white);
g.fillOval(50,50,130,80);
g.fillOval(120,50,110,80);

g.setOval(Color.yellow);
g.fillOval(660,70,80,80);
g.drawLine(660,70,80,80);
g.drawLine(700,30,700,190);
g.drawLine(630,50,760,170);
g.drawLine(630,170,760,50);

}

public static void main(String[] args) {

House h = new House();
}
}


 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brian Devadason wrote:Heres the program can some one tell me what to


1. First of all, sort out the compiler errors that you didn't tell us about. And if you don't have any compiler errors, then you need to PostRealCode <- link
2. Learn the correct way of Performing Custom Painting. It is not by overriding paint() in a top level window like JFrame.
3. Learn about the Event Dispatch Thread, and how to deal with Concurrency in Swing. You can gloss over much of that section for now, and return to it later, but make sure you understand how to 'kick off' your GUI on the EDT.
4. Last but not least: when posting code on the forum, UseCodeTags <- link

And welcome to the Ranch!
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the programming exercise seems to be - fix the code so it compiles and runs.

if so, just fix them one at a time - the top one, don't worry about the rest until the top one is fixed.
recompile/rerun/repeat
reply
    Bookmark Topic Watch Topic
  • New Topic