Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Damn you Swing!  (Read 2002 times)
0 Members and 1 Guest are viewing this topic.
Offline Shin_Bet

Senior Newbie





« Posted 2006-01-21 21:55:56 »

Ok, i've made a variety of panels which ive put onto my frame. The problem is everything is gray! I used paintcomponent to put a nice background in and the damn thing doesnt show up! Help please? Huh Huh
Offline Grand Poeba

Junior Member





« Reply #1 - Posted 2006-01-21 23:51:51 »

do u use super.paint(g)?

layout used?

c-an you give some more info
Offline Shin_Bet

Senior Newbie





« Reply #2 - Posted 2006-01-21 23:59:54 »

class OpeningScreen extends JFrame implements ActionListener{
   Image BackGround = Toolkit.getDefaultToolkit().getImage("BackGroundOpen.gif");
   JPanel TeamPanel = new JPanel(); Border b1 = BorderFactory.createTitledBorder("Choose Your Team");
   JPanel HostPanel = new JPanel(); Border b2 = BorderFactory.createTitledBorder("Are you Host?");
   JPanel PlayPanel = new JPanel(); Border b3 = BorderFactory.createTitledBorder("Play!");
   Box LabelPanel = Box.createVerticalBox();
   boolean bool = false;
   JButton RED = new JButton("Red Team"); JButton BLUE = new JButton("Blue Team");
   JButton Host = new JButton("Host"); JButton Leech = new JButton("Leech");
   JButton Play = new JButton("Play!");
   JLabel QHost = new JLabel(); JLabel QTeam = new JLabel();
   char OpeningTeam = ' ';
   char OpeningHost = ' ';
   Test t;

   OpeningScreen(){
      Play.addActionListener(this);
      RED.addActionListener(this);
      BLUE.addActionListener(this);
      Host.addActionListener(this);
      Leech.addActionListener(this);
      Font f = new Font("Comic Sans MS", Font.PLAIN, 30);
      Color c = Color.BLUE;
      PlayPanel.setLayout(new BorderLayout());
      HostPanel.setBorder(b2); TeamPanel.setBorder(b1); PlayPanel.setBorder(b3);
      PlayPanel.add(Play, BorderLayout.CENTER);
      HostPanel.add(Host); HostPanel.add(Leech);
      TeamPanel.add(RED); TeamPanel.add(BLUE);
      QHost.setFont(f); QTeam.setFont(f);
      QHost.setForeground(c); QTeam.setForeground(c);
      //LabelPanel.add(Box.createHorizontalStrut(1));
      LabelPanel.add(Box.createRigidArea(new Dimension(30,60)));
      LabelPanel.add(QHost);
      LabelPanel.add(Box.createVerticalStrut(20));
      LabelPanel.add(QTeam);
      this.setSize(400,400);
      this.setLayout(new BorderLayout());
      this.add(HostPanel, BorderLayout.NORTH);
      this.add(TeamPanel, BorderLayout.SOUTH);
      this.add(PlayPanel, BorderLayout.EAST);
      this.add(LabelPanel, BorderLayout.CENTER);
      this.setVisible(true);
   }

    //public void paintComponent(Graphics g) {
    ///   g.drawImage(BackGround,10,10,this);
    //}


   public void actionPerformed(ActionEvent e){
      if(e.getSource() == Play){bool = true;t = new Test();}
      if(e.getSource() == RED){QTeam.setText("Red  ");OpeningTeam = 'R';}
      if(e.getSource() == BLUE){QTeam.setText("Blue ");OpeningTeam = 'B';}
      if(e.getSource() == Host){QHost.setText("Host ");OpeningHost = 'H';}
      if(e.getSource() == Leech){QHost.setText("Leech");OpeningHost = 'L';}
   }


here is the code. i know it probaly sucks, but its for a final project, and i need to get that damn image there!Thanks
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grand Poeba

Junior Member





« Reply #3 - Posted 2006-01-22 01:06:41 »

is it an image with transparant parts?

try adding super.paint(g);
to paint method
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #4 - Posted 2006-01-22 19:37:31 »

If this is really for a final project my first advice would be: please adhere to the java coding conventions. Identifiers should start with lower case letters. Also, your paintComponent method is obviously commented out. Third, if you add a large number of panels to to frame they will cover it. Therefore it doesn't matter what you draw in the paintComponent method, since the nontransparent panels will simply be drawn there instead.
Offline Shin_Bet

Senior Newbie





« Reply #5 - Posted 2006-01-24 23:30:16 »

Ok, thanks for the advice. It is only commented out because i was working on it without the image at the time i copied and pasted it. Not an error, i assure you.
How do i make an image semi-transparent?

Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #6 - Posted 2006-01-25 16:44:17 »

I suppose what you want is to make the backgrounds of those PANELS transparent. That is done by calling .setOpaque(false). If you still want to tinker with images, check out java.awt.Transparency.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (48 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!