codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  setSize and setTitle  strider at 20:03 on Tuesday, February 21, 2006
 

I'm trying to create a simple program within an applet and I cant get it to do anything after I set my size. Here is the whole program, its very basic and not meant to be viewed in a browser.

import javax.swing.*;
import java.awt.*;

public class GettingGraphic extends JApplet
{

public void paint( Graphics fun )
{

setSize(1000,1000);

//Sets background color to orange

setBackground (Color.orange);

//Welcome Message with set font command

fun.setFont(new Font("Broadway", Font.BOLD, 36));
fun.drawString("Welcome to Strider\'s Getting Graphic",30,40);



}
}

I would also like to set a title for the applet, any suggestions?

Thanks

Strider

  Re: setSize and setTitle  crwood at 23:32 on Tuesday, February 21, 2006
 

setSize should go in the init method.
Titles usually go with top–level containers. You can try the setWindowDecorationStyle method (j2se 1.4+).

// <applet code="GettingGraphic" width="400" height="400"></applet>
// use: >appletviewer GettingGraphic.java
import java.awt.*;
import javax.swing.*;

public class GettingGraphic extends JApplet
{
public void init()
{
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
cp.add(new GraphicPanel());
setSize(1000,600);
JRootPane rootPane = getRootPane();
System.out.println(rootPane.getWindowDecorationStyle()); // 0
// see JRootPane api for other choices of style
rootPane.setWindowDecorationStyle(JRootPane.FRAME); // 1
}
}

class GraphicPanel extends JPanel
{
Font font;

public GraphicPanel()
{
font = new Font("Broadway", Font.BOLD, 36);
setBackground(Color.orange);
}

protected void paintComponent( Graphics fun )
{
super.paintComponent(fun);
int w = getWidth();
int h = getHeight();
//Sets background color to orange
// don't need the call (above) to "super" if you do this:
//setBackground (Color.orange);
//fun.clearRect(0,0,w,h);
// ...or this:
//fun.setColor(Color.orange);
//fun.fillRect(0,0,w,h);
//Welcome Message with set font specified
fun.setFont(font);
fun.drawString("Welcome to Strider\'s Getting Graphic",30,40);
}
}









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Digital.Canal.Software.V2013
•  Altair_HyperWorks_12.0.1_Win64
•  Global.mapper.V15.0
•  ESI.PAM-RTM.V2010.0
•  KISSsoft.03.2013E.SP5
•  Technical.Toolboxes.Pipeline.Toolbox.2013.Enterprise.v15.0.0
•  Simprotek.Simprosys.V3.0
•  Ricardo.SABR.V6.0p1
•  PSIM.V9.2


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2013