Annoying program, please help

I wrote an JFrame draw program which can work well by itself class D. However, when I call it from the other class B using B's JFrame, the drawing can't display. What happens?
import java.io.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
public class D extends JApplet{
    public void init() {
    public void paint(Graphics g) {
  Graphics2D g2=(Graphics2D)g;
     g2.draw(new Line2D.Double(0,0,100,100));
/*public static void main(String[] args){
        JFrame f = new JFrame("2D draw");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        JApplet applet = new D();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.pack();
        f.setSize(new Dimension(500,500));
        f.show();
When I use in B class:
JFrame f=new JFrame();
Container content=f.getContentPane();
JButton button4=new JButton("Test");
     ActionListener b4_al=new ActionListener(){
             public void actionPerformed(ActionEvent ae){
                try{
                JApplet applet = new D();
               content.add("Center", applet);
               applet.init();
               f.pack();
               f.setSize(new Dimension(500,500));
               f.show(true);
       }catch (Exception e){}
        button4.addActionListener(b4_al);

Worked for me.
Some few changes I made (had to make the frame final,
add the button to the frame, size and show the frame).
(sorry 'bout name of MouseMoveTest, just use it as my general test file now...)
import java.io.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
public class MouseMoveTest {
  public static void main (String[] args) {
       final JFrame f=new JFrame();
       final Container content=f.getContentPane();
       JButton button4=new JButton("Test");
       ActionListener b4_al=new ActionListener(){
            public void actionPerformed(ActionEvent ae){
                 try{
                      JApplet applet = new D();
                      content.add("Center", applet);
                      applet.init();
                      f.pack();
                      f.setSize(new Dimension(500,500));
                      f.show(true);
                 }catch (Exception e){}
       button4.addActionListener(b4_al);
       content.add(button4);
       f.setSize(new Dimension(500,500));
       f.show(true);
class D extends JApplet {
     public void init() {
     public void paint(Graphics g) {
          Graphics2D g2=(Graphics2D)g;
          g2.draw(new Line2D.Double(0,0,100,100));
}

Similar Messages

  • How do i get rid of the spinning wheel?  it's quite annoying.  Please help!!

    How do I get rid of the spinning beach ball?  It's quite annoying.  Please help. 

    You want this moved to OS X forum? to MBP? An FAQ on system repair and maintenance?
    Try booting form OS X DVD and go to Utility: Disk Utilty and Repair Disk Drive - for starters.
    Unplug everything.
    Reboot holding Shiftkey - called Safe Boot, might want to look that up.
    Add more RAM, free up disk space. Delete temp and cache files (I don't recommend using a "cache cleaning utility" though Onyx has been around for years).

  • My MacBook get's hot really quick and then discharge's quickly without opening any program, please help.

    My MacBook get's hot really quick and then discharge's quickly without opening any program, please help.
    I have checked the cooling fan, and it's working, and I took it to an IT technician and he said my hardware is allright, so is it a problem from the OS it self??
    OS X(10.8.5)

    Restart with the Option key held down and the Mac OS X install disk inserted, provide the firmware password, click on the DVD, press the button with the straight arrow, access the firmware settings, disable the password, and use FireWire Target Disk mode. If you can't do that or it doesn't work, contact Apple.
    (38384)

  • I have windows 8 and I got this error "Adobe Photoshop has stopped working" whenever I start a program. please help. how can I fix this problem? many thanks

    i have windows 8 and I got this error "Adobe Photoshop has stopped working" whenever I start a program. please help. how can I fix this problem? many thanks

    Please read these and proceed accordingly:
    http://blogs.adobe.com/crawlspace/2012/07/photoshop-basic-troubleshooting-steps-to-fix-mos t-issues.html
    http://forums.adobe.com/docs/DOC-2325

  • One of my ipod apps has frozen on waiting, I've tried everything. (Restarting it, plugging it into the computer, in setting etc...)  and also I tried deleting it, but no "X" comes up. but nothing is working. Really annoyed. :( please help.  ,

    one of my ipod apps has frozen on waiting, I've tried everything. (Restarting it, plugging it into the computer, in setting etc...)  and also I tried deleting it, but no "X" comes up. but nothing is working. Really annoyed. :( please help.  ,

    See:
    Downloading apps stuck on waiting...: Apple Support Communities
    \Waiting applications: Apple Support Communities

  • Error while running HelloWorld program Please Help me

    Hi Friends! I am doing my hello world program...while running i m getting the below error...please help me regarding this...
    The target WSCO.java cannot be started as a servlet, because the class oracle.apps.ak.ws.webui.WSCO does not extend javax.servlet.GenericServlet.
    The target WSCO.java cannot be started as an application, because the class oracle.apps.ak.ws.webui.WSCO does not have a main method.

    Hi,
    For building a simple hello world page, follow these steps:
    1) Create a New OA Workspace and a new OA Project. Make sure that package name should be prefixed by some custom name like:
    xx.oracle.apps.ak.hello
    2) Create new OA Page under webui:
    xx.oracle.apps.ak.hello.webui.XxHelloWorldPG
    3) Create a new Application module, XxHelloWorldAM in below package:
    xx.oracle.apps.ak.hello.server.XxHelloWorldAM
    4) Attach this AM to your XxHelloWorldPG.
    5) Now create regions and items under pageLayout region of this page.
    6) Add a controller to pageLayout region in webui package:
    xx.oracle.apps.ak.hello.webui.XxHelloWorldCO
    Also you can add a button on the page and write some code in PFR method of your controller.
    --Sushant                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Problem compiling my first program; Please Help me!

    Please HELP, what am I doing wrong?
    For over 5hours I have been trying to figure out how to compile a simple Hello world program using sdk1.3.1_02/j2re1.3.1_02 and I am getting the following errors: helloworld.java:2 cannot resolve symbol
    symbol : class string
    location : class helloworld
    cannot reolve the string symbol
    symbol : class out
    location : package system
    I want to program in java so badly but I am trying to get my environment set so that I can take off. To compile my first program has been a disaster!!
    This is my path:
    SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\JDK1.3.1_02\BIN
    Thanks very much in advance
    ::(

    Java is case sensitive,
    use String instead of string. and System.out instead of system.out
    Sudha

  • I paid for membership and cannot access the program please help???????

    I paid for the program and cannot access it please help may i talk to someone?

    Did you install the trial or any update version?
    What were the instructions when you purchased?

  • Connecting two programs - please help

    Hi, I'm new here, so I'd like to say 'hi' to everyone :) I'm a freshman in the java comunity, so please be gentle.
    Firs of all I'd like to ask how to resolve the first problem. I've got the code which is responsible for convert a html document to the txt file. It looks like:
    import javax.swing.text.html.parser.*;
    import javax.swing.text.html.*;
    import javax.swing.text.*;
    import javax.swing.*;
    import java.io.*;
    public class TextFromHtml extends HTMLEditorKit.ParserCallback{
    static String trimmss(String o){
       return (o.trim()).replaceAll("\\s+", " ");
    public void handleText(char[] data, int pos){
    try{
          String o = new String(data);
          PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("test.txt", true)));
          o = trimmss(o);
          pw.println(o);
          //pw.close();
         catch (IOException exc){}      
    System.out.println(new String(data));
      public static void main(String args[]){
        try{
          String s = JOptionPane.showInputDialog("Enter the name of the file you want to convert from html to txt.");     
          Reader r = new FileReader(s);
          ParserDelegator parser = new ParserDelegator();
          HTMLEditorKit.ParserCallback callback = new TextFromHtml();
          parser.parse(r, callback, true); 
        catch (IOException e){
          e.printStackTrace();
         System.exit(0);
    }But unfortunately I don't know how to change this code to obtain such situation as making a new txt file without blank spaces > 0 and erasing the \n new lines. I'd like to get a txt file, which contains of line-by-line text. Could you please help me - tell & show me how to do that? I'd be very grateful
    Regards, skullscape.

    Hi Skullscape,
    My apologies for not getting a response on this forum, but this may have been because this is a fairly generic Java programming question, rather than an issue specific to the JSE product, the purpose of this particular forum.
    So may I suggest that you check out http://java.sun.com/ which has a full set of facilities for those such as yourself who are new to Java programming.
    Although by now you nay not be such a novice :-)

  • Error 13019 really getting annoyed now please help!

    I have an iPod touch 1st generation. I have the latest 3.0 update and I have the latest iTunes update. Yesterday my iPod was working fine. Now, every time I try to sync music, iTunes backs up my iPod but then gives me error 13019. I know what it means, but how do I get rid of it? I havent done anything to my ipod or iTunes that would give it an error. I havent updated anything so why would it give me errors? I have already tried resetting my computer and iPod. It says my iPod can't be synced. But I know it can because I can put movies, apps, and everything else on it. Just not music. Please help me with this. I am really getting annoyed with all my iPod problems now!!!
    Message was edited by: nhnkj

    hamish72 wrote:
    Is his up bandwidth of 828 an indication  he's line is upgraded and is not the modulation shown in stats his line modulation ? 
    Hi hamish72
    there have been previous posts on the forum where the modulation has changed to 992.5 with the change in upload speed but with download still on adslmax level.  either getting mods involved or phoning sales and agreeing a new contract appear the solution to getting download upgraded
    If you like a post, or want to say thanks for a helpful answer, please click on the Ratings star on the left-hand side of the post.
    If someone answers your question correctly please let other members know by clicking on ’Mark as Accepted Solution’.

  • Deleted apple mail program, please help!

    I deleted mail, and can't seem to find it within the 'install bundled software' on the discs which came with the computer (mac os x install discs 1 & 2). How can I go about reinstalling the program? Please Help...

    Hi Rob, and a warm welcome to the forums!
    Is that the Install Disk?
    Custom installs in Mac OS X 10.4...
    http://docs.info.apple.com/article.html?artnum=301229
    "Here's a list of all the custom installation options available with Optional Installs.mpkg:
    * Applications
    o Address Book 4.0
    o iCal 2.0
    o iChat 3.0
    o iTunes 4.7.1
    o Mail 2.0
    o Oxford Dictionaries
    o Safari 2.0
    o X11"
    If that isn't the case, get Pacifist...
    http://www.charlessoft.com/
    then extract what you need from your Install Disk.

  • Problem with simple drawing program - please help!

    Hi,
    I've only just started using Java and would appreciate some help with a drawing tool application I'm currently trying to write.
    The problem is that when the user clicks on a button at the bottom of the frame, they are then supposed to be able to produce a square or circle by simply clicking on the canvas.
    Unfortunately, this is not currently happening.
    Please help!
    The code for both classes is as follows:
    1. DrawToolFrame Class:
    import java.awt.*;
    import java.awt.event.*;
    public class DrawToolFrame extends Frame
    implements WindowListener
    DrawToolCanvas myCanvas;
    public DrawToolFrame()
    setTitle("Draw Tool Frame");
    addWindowListener(this);
    Button square, circle;
    Panel myPanel = new Panel();
    square = new Button("square"); square.setActionCommand("square");
    circle = new Button("circle"); circle.setActionCommand("circle");
    myPanel.add(square); myPanel.add(circle);
    add("South", myPanel);
    DrawToolCanvas myCanvas = new DrawToolCanvas();
    add("Center", myCanvas);
    square.addMouseListener(myCanvas);
    circle.addMouseListener(myCanvas);
    public void windowClosing(WindowEvent event) { System.exit(0); }
    public void windowOpened(WindowEvent event) {}
    public void windowIconified(WindowEvent event) {}
    public void windowDeiconified(WindowEvent event) {}
    public void windowClosed(WindowEvent event) {}
    public void windowActivated(WindowEvent event) {}
    public void windowDeactivated(WindowEvent event) {}
    2. DrawToolCanvas Class:
    import java.awt.*;
    import java.awt.event.*;
    public class DrawToolCanvas
    extends Canvas
    implements MouseListener, ActionListener {
    String drawType="square";
    Point lastClickPoint=null;
    public void drawComponent(Graphics g) {
    if (lastClickPoint==null) {
    g.drawString("Click canvas first",20,20);
    } else {
    if (drawType.equals("square")) {
    square(g);
    else if (drawType.equals("circle")) {
    circle(g);
    public void actionPerformed(ActionEvent event) {
    if (event.getActionCommand().equals("square"))
    drawType="square";
    else if (event.getActionCommand().equals("circle"))
    drawType="circle";
    repaint();
    public void mouseReleased(MouseEvent e) {
    lastClickPoint=e.getPoint();
    public void square(Graphics g) {
    g.setColor(Color.red);
    g.fillRect(lastClickPoint.x, lastClickPoint.y, 40, 40);
    g.setColor(Color.black);
    public void circle(Graphics g) {
    g.setColor(Color.blue);
    g.fillOval(lastClickPoint.x, lastClickPoint.y, 40, 40);
    g.setColor(Color.black);
    public void mouseEntered(MouseEvent e) {}
    public void mouseExited(MouseEvent e) {}
    public void mousePressed(MouseEvent e) {}
    public void mouseClicked(MouseEvent e) {}
    Any help would be appreciated!

    Some of the problems:
    1) nothing calls drawComponent(Graphics g)
    2) Paint(Graphics g) has not been overriden
    3) myCanvas is declared twice: once as an instance variable to DrawToolFrame, and once local its constructor. Harmless but distracting.

  • HT6114 hi all, my cisco Router link sys E2000 stop working need to up date Mac OS 10.4.9 or 10.5.8 or 10.6.1later how do i find this program please help

    hi all, my cisco router linksys E2000 stop working need to up date Mac OS 10.5.8 later or 10.5.8 or later or 10.6.1 or later where do i find this up date im new on mac computer please help

    I just visited the Linksys e2000 page, I think you need 10.6. You can buy it here:
    http://store.apple.com/us/product/MC573Z/A/mac-os-x-106-snow-leopard

  • Can't Install Windows Program -PLEASE HELP

    This is now my 3rd attempt at trying to install stupid Windows on my Mac (need for merchant account and quickbooks).
    Anyway, I ordered Microsoft XP 2000 Home OEM. I actually go a link from a person on this board. I am a little concerned because the packaging and CD says 'to be distributed with a new PC'. It has been my problem that I have been using Free software and it won't take the Free version.
    Okay, here is what I have done so far
    1. Partitioned HD for Windows in Bootcamp
    2. Inserted new Windows CD
    3. Screen goes White(ish) and you here the Windows (bong).
    4. CD ejects
    5. Screen goes black and then you get a message that says 'no bootable device insert boot disk press any key)
    6. Reinsert CD, nothing happens
    Concern is there is some old Windows on this when I have tried to download in the past. I however cannot find anywhere and believe that I ahve removed everything. I did download a trial version of Parallels and tried to download another Windows version, but I removed everything from my computer that had to do with Paralles (or so I thought...even emptied trash).
    So, I am DESPERATE!! PLEASE HELP
    5. Insert

    Here is where I am now...
    I was able to remove Windows from Bootcamp.
    I go through the set up again.
    I get through everything and it says the computer will reboot and continue with setup.
    During the reboot, the disk ejects, then I get a black screen that says Disk Error press any key. Nothing happens when you press a key and you have to manually shut down. When I reboot, I get two icons, MAC HD and Windows HD. Yet, nothing comes up when I click on Windows HD.
    PLEASE SOMEONE HELP ME. I have spent hours on this and I really don't think I am THAT stupid.
    I know people don't get paid to help, but if someone could walk me through this. Mac won't help me.

  • I'm trying to download a 7 dollar game but it won't let me download it because it keeps telling me to come here to apple support an it's really annoying. Please help.

    Please help

    It's not telling you to come to the support communities.  It's telling you to contact iTunes store support.
    http://www.apple.com/lae/support/itunes/contact/.

Maybe you are looking for

  • Error in Adapter Engine

    Hi Experts, In the Component Monitoring, the ADAPTER ENGINE have a RED status, show the message: Details for Ping Status Message: Cannot construct correct URL for runtime check using entries in SLD for component af.pid.<hostname>; correct entries in

  • Size in InputField size in FileUpload

    Does anybody know why a htmlb:InputField with size="20" is much smaller that a htmlb:fileupload with size="20"? <htmlb:inputField id = "att" size = "20"/>     <htmlb:fileUpload id = "upl" size = "20" onUpload = "HdlUp"/>

  • SQL TRACE/TKPROF VS SQL ACCESS ADVISOR

    Hi All, Can anyone please tell me what's the exact difference between SQL TRACE/TKPROF and SQL ACCESS ADVISOR in Oracle 10g.(By showing some examples) And also why should I go for SQL ACCESS ADVISOR ?? (Since I have used the former all these days) :)

  • My FSG report drill down redirectly to PROD url in the cloned instance

    Hi All, Version : R12.1.3 DB : 11.2.0.3 My FSG drill down is giving error in my DEV instance ,as the drill down is taking me to wrong url(PRODUCTION) Anyone know where to define the hostname for drill down RG. Thanks

  • Premiere cs6 slowed significantly after creating a non-admin user on win7

    hi ok so here is my problem i have a computer on work operating win7 x64 sp1 and i installed cs6 master collection on it and it was working fine. recently and in order to avoid unwanted installed programs on the machine "namly games" we created a nor