Easy swing question for Java friends

Hi could somebody test this short application and tell me why the "DRAW LINE" button doesnt draw a line as I expected?
thank you very much!
Circuitos.java:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.awt.geom.*;
public class Circuitos extends JApplet {
     protected JButton btnRect;
     protected Terreno terreno;
     private boolean inAnApplet = true;
     //Hack to avoid ugly message about system event access check.
     public Circuitos() {
          this(true);
     public Circuitos(boolean inAnApplet) {
        this.inAnApplet = inAnApplet;
          if (inAnApplet) {
               getRootPane().putClientProperty("defeatSystemEventQueueCheck",Boolean.TRUE);
     public void init() {
          setContentPane(makeContentPane());
     public Container makeContentPane() {
          btnRect = new JButton("DRAW LINE");
      btnRect.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            terreno.pintarTramo();
          terreno = new Terreno();
          JPanel panel = new JPanel();
          panel.setLayout(new BorderLayout());
          panel.add("North",btnRect);
          panel.add("Center",terreno);
          return panel;
     public static void main(String[] args) {
        JFrame frame = new JFrame("Dise�o de Circuitos");
          frame.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                    System.exit(0);
          Circuitos applet = new Circuitos(false);
          frame.setContentPane(applet.makeContentPane());
          frame.pack();
          frame.setVisible(true);
}Terreno.java:
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class Terreno extends JPanel {
     Graphics2D g2;
     public Terreno() {
          setBackground(Color.red);
          setPreferredSize(new Dimension(500,500));
     public void paintComponent(Graphics g) {
          super.paintComponent(g);
      g2 = (Graphics2D) g;
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);    
     public void pintarTramo () {     
          Point2D.Double start   = new Point2D.Double(250,250);
          Point2D.Double end     = new Point2D.Double(250,285);
          g2.draw(new Line2D.Double(start,end));            
}

I don't think the date I became a member has anything to do with it. Yes, I signed up a year ago to ask a question or two when I didn't know anything. It wasn't until recently have I started to use this forum again, only to try and help people as well as ask my questions. It took me a year to get to this point to where I can actually answer questions instead of just asking. So don't be silly and judge a person based on their profile.
Secondly, I agree with you, the search utility is great. I use it all the time and usually I'll find my answers, but if I don't is it such a pain in the butt for you to see the same problem posted again?? I know how much you want people to use the resources available before wasting forum space with duplicate questions, but it's not going to happen. Some people are not as patient and you being a butt about it won't stop it.
My point in general is that there are nice ways to help people and even rude ways, and your comments at times come across rude to me, even condescending. You have a lot of knowledge, therefore certain things seem trivial to you... but try to understand where some of the new people are coming from. The Swing tutorial is extremely helpful but if you don't understand the concept of programming or java that well... then it can be overwhelming and you don't know where to start. It's a huge tutorial and when people are stuck they just want an answer to their one question. Most figure it's easier to ask someone who already knows instead of reading an entire tutorial to get their answer.
I've learned by both methods, by taking the time to research it myself and by asking a lot of questions. I have the time. Some don't. Please realize that not everyone is like you and they will continue to ask whether you like it or not. You have a choice, either help them or not.

Similar Messages

  • Swing Tutorial for Java version 1.4.2

    Hi all, where the subject can be found?
    Current tutorial for Swing that is present on site http://java.sun.com/docs/books/tutorial/uiswing/
    is for Java 6 only.
    I am particularly interested in filtering JTable.
    Thanks in advance.

    Here is a link to the 1.5 tutorial which I believe is the same as the 1.4.2 tutorial:
    https://www.cs.auckland.ac.nz/references/java/java1.5/tutorial/uiswing/TOC.html

  • Easy Slide Question for Website

    Easy question for u guys.
    What is the easiest way to create slider header such as these websites ->
    http://www.pclsolutions.com/
    http://www.alivre.com/
    What is the easies way of doing it???
    Dreamweaver has so many options, and I have very limited time so I was wondering if anybody could give me the easy answer here so I can proceed further.
    Thank you in advance guys.

    Log-in to the Adobe Widget Exchange and grab Spry Content Slideshow
    http://labs.adobe.com/technologies/widgetbrowser/
    WOW slider
    http://wowslider.com/
    NIVO slider
    http://nivo.dev7studios.com/
    just to name a few...
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists 
    http://alt-web.com/
    http://twitter.com/altweb
    http://alt-web.blogspot.com/

  • Beginner question for java appelets regarding positioning.

    I am creating a java appelet, and I am having issues positioning labels, text boxes , buttons. Is there a way I can specify where each is positioned?
    Thank you!
    for example here is my code:
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    public class AdditionOfFractions extends Applet implements ActionListener {
        Label Num1Lbl = new Label("num1");
        Label Num2Lbl = new Label("num2");
        Label Den1Lbl = new Label("den1");
        Label Den2Lbl = new Label("den2");
        Label ResultLbl = new Label("Result");
        TextField Num1Text = new TextField(4);
        TextField Num2Text = new TextField(4);
        TextField Den1Text = new TextField(4);
        TextField Den2Text = new TextField(4);
        TextField ResultText = new TextField(4);
        Button ComputeBtn  = new Button("Compute");
        Button ExitBtn  = new Button("Exit");
        public void actionPerformed(ActionEvent thisEvent)throws NumberFormatException {
            if(ComputeBtn.hasFocus()){
                System.out.println("test");
                int num1 = Integer.parseInt(Num1Text.getText());
                int num2 = Integer.parseInt(Num2Text.getText());
                int den1 = Integer.parseInt(Den1Text.getText());
                int den2 = Integer.parseInt(Den2Text.getText());
                int newDen = 0;
                if(den1 != den2){
        public void init()
            //initialise
            ResultText.setEditable(false);
            ComputeBtn.addActionListener(this);
            ExitBtn.addActionListener(this);
            //add components
            add(Num1Lbl);
            add(Num1Text);
            add(Den1Lbl);
            add(Den1Text);
            add(Num2Lbl);
            add(Num2Text);
            add(Den2Lbl);
            add(Den2Text);
            add(ResultLbl);
            add(ResultText);
            add(ComputeBtn);
            add(ExitBtn);
    }

    797737 wrote:
    I am creating a java appelet, and I am having issues positioning labels, text boxes , buttons. Is there a way I can specify where each is positioned?Definitely, for your simple Applet you'll probably just want to use a <tt>java.awt.GridLayout</tt>. This will effectively position all your components in a grid pattern that you set in the contructor.
    //make a grid 4 rows, 2 columns
    GridLayout gridLayout = new GridLayout(4, 2);Then you'll need to set this for the Applet like so:
    pubic void init(){
      //initial your components as usual
      setLayout(gridLayout);
      //add components as usual;
    }Now 37, you don't want the <tt>actionPerformed()</tt> method to throw any Exceptions. Instead put your code inside a try/catch block:
    public void actionPerformed(ActionEvent ae)
      int num1, num2, den1, den2;
      try {
        num1 = Integer.parseInt(Num1Text.getText());
        num2 = Integer.parseInt(Num2Text.getText());
        den1 = Integer.parseInt(Den1Text.getText());
        den2 = Integer.parseInt(Den2Text.getText());
      catch(NumberFormatException)
        //provide DEFAULT VALUES HERE;
    }37, try to use the <tt>EventObject.getSource()</tt>, or <tt>ActionEvent.getActionCommand()</tt>.
    public void actionPerformed(ActionEvent ae) {
      //Choose one of the following lines
      //line 2 is probably a better choice here
      Button button = (Button)ae.getSource();
      String actionCommand = ae.getActionCommand();
      if(actionCommand.equals("Compute"))
        //try/catch block here
        //compute here
        //set results
        // OR create a compute() that
        // includes all three lines above
    }Now OP, I have a question for you. Do you see a way to LIMIT the values of <tt>num1, num2, den1, den2</tt> so that your program is safe to run -- so that the compute formula does not throw any ArithmeticExceptions?

  • Tough question for java beginning expert

    Hi, y'all,
    I couldn't compile "HelloWorld". I downloaded jdk1.3.1_01 and tried to compile "HelloWorld" in MS-DOS. However, the error is: "cannot read HelloWorld.java." I couldn't figure out what's wrong.
    Here's my source code:---------
    class HelloWorld{
    public static void main (String[ ] args) {
    System.out.println("What's wrong with you?");
    Here's my DOS command:--------
    Microsoft Windows 2000 [Version 5.00.2195]
    (C) Copyright 1985-2000 Microsoft Corp.
    C:\>cd java\
    C:\java>dir
    Volume in drive C has no label.
    Volume Serial Number is 07D1-0B0D
    Directory of C:\java
    11/23/2001 01:06p <DIR> .
    11/23/2001 01:06p <DIR> ..
    11/24/2001 01:37a 135 HelloWorld.java.txt
    1 File(s) 135 bytes
    2 Dir(s) 76,506,595,328 bytes free
    C:\java>javac HelloWorld.java
    error: cannot read: HelloWorld.java
    1 error
    C:\java>cd c:\
    C:\>jdk1.3.1_01\bin\javac HelloWorld.java
    error: cannot read: HelloWorld.java
    1 error
    C:\>
    Please Help me. Thanks.
    lee

    Yes, notepad has this "helpful" feature of adding ".txt" to the name of files whose extension is not registered. You'll need to register the "java"-file type if you don't want to get problems like this again.
    On the other hand, notepad is not a very text editor for programming in the first place, so I recommend getting a more adept one. Features that you should be looking for include sytax highlighting and bracket matching - they make it easier to spot stupid typos.

  • Simple Swing Question for HTML

    I am trying to load a web page and I know how to do that using JEditorPane or JTextPane, but what I need to do is for the program to be able to load the page, enter a username and password in 2 of the <input> text fields and then submit it.
    IMPORTANT: I don't mean that I or a user would login, I mean the program I write would auto login.
    Does anyone know how this is accomplished?
    I do know how to do it with Javascript, but this needs to be a Java application.
    Once loaded I would then do some web scraping, again with Java, this I think I know how to do.
    Thanks,
    Dan

    Hi!
    Maybe you can find one part of the solution here (Reply 2,3,4)
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=285307
    or here
    http://forum.java.sun.com/thread.jspa?threadID=786631&messageID=4470190#4470190
    This would be the part for getting the username and password.
    How to submit it I do not know. I would look at class HttpURLConnection and the tutorial: http://java.sun.com/docs/books/tutorial/networking/urls/index.html

  • Easy Facebook Question for you!!

    When i'm trying to post a message or write on someones wall i type in the textbox, however it doesn't word wrap..Is there a way to have it word wrap?
    Also if i move my cursor out of the textbox, i can never start my message where i ended off.  I go on to the text box and slowly scroll to the end of my msg to continue, i click the trackball and it moves the cursor somewhere else.
    Can someone tell me if its possible to get the cursor back to the end of the msg so i can continue posting if i where to move my cursor..
    Thanks

    Let me recommend you use the Facebook for BlackBerry application.
    On your Facebook mobile website page, scroll to the bottom and you'll a link to download.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • Quick easy String question for u pros

    How can I add a string to a string. Each time I try the output is blank...:(

    How can I add a string to a string. Each time I try the output is blank...:(There are a variety of ways. Don't make us guess at what you're trying to do.
    Please post a short, concise, executable example of what you're trying to do. This does not have to be the actual code you are using. Write a small example that demonstrates your intent, and only that. Wrap the code in a class and give it a main method that runs it - if we can just copy and paste the code into a text file, compile it and run it without any changes, then we can be sure that we haven't made incorrect assumptions about how you are using it.
    Post your code between [code] and [/code] tags as described in Formatting Help on the message entry page. Cut and paste the code, rather than re-typing it (re-typing often introduces subtle errors that make your problem difficult to troubleshoot). Please preview your post when posting code.
    Please assume that we only have the core API. We have no idea what SomeCustomClass is, and neither does our collective compiler.

  • I would like to buy an iPhone for my friend in Iceland.  Two questions: will the phone work with complete utility in Iceland, and if so, what should I do to confirgure it while in the USA so that it can have full utility in Iceland?

    I would like to buy an iPhone for my friend in Iceland.  Two questions: will the phone work with complete utility in Iceland, and if so, what should I do to confirgure it while in the USA so that it can have full utility in Iceland?

    Bad idea. There are no supported iPhone carriers in Iceland, thus some features may or may not work. Further, there will be no warranty or support for a US purchased iPhone in Iceland...your friend will be on their own. If you still want to go down this road, make sure you purchase an officially unlocked iPhone(GSM model) directly from Apple.

  • Accelarate the Linux ATI Graphics card  for java Swing application

    Hi All,
    I am using a ATI Radeon 9550 Graphic card in LFS (Linux from the scratch) environment. I want to enable the OpenGL-based pipeline for Java Swing application. I tried the -Dsun.java2d.opengl=true . But the Java swing application getting very slow.
    How to overcome this problem?
    Any one give the procedure to Accelerate ATI graphics card for Java Swing Application
    How to verify Java swing use ATI graphics card ?
    Thanks in advance..
    Prabhu.S

    Hi All,
    I am using a ATI Radeon 9550 Graphic card in LFS (Linux from the scratch) environment. I want to enable the OpenGL-based pipeline for Java Swing application. I tried the -Dsun.java2d.opengl=true . But the Java swing application getting very slow.
    How to overcome this problem?
    Any one give the procedure to Accelerate ATI graphics card for Java Swing Application
    How to verify Java swing use ATI graphics card ?
    Thanks in advance..
    Prabhu.S

  • Question on forte for java

    Hi,
    I'm developing using the Forte for JAVA ide, but I get an error though i know certainly that my code is correct.
    I get this error:
    Tue Nov 06 11:35:29 CET 2001: java.lang.NoSuchMethodError: Posted StackTrace
    Annotation: Exception occurred in Request Processor
    org.openide.util.RequestProcessor$Holder: Posted StackTrace(task org.netbeans.modules.web.core.jsploader.TagLibParseSupport$ParsingRunnable@772046 [-2433, 9, -1])
    at org.openide.util.RequestProcessor$Task.createHolder(RequestProcessor.java:322)
    at org.openide.util.RequestProcessor.post(RequestProcessor.java:100)
    at org.openide.util.RequestProcessor.postRequest(RequestProcessor.java:185)
    at org.netbeans.modules.web.core.jsploader.TagLibParseSupport.parseObject(TagLibParseSupport.java:110)
    at org.netbeans.modules.web.core.jsploader.TagLibParseSupport.prepare(TagLibParseSupport.java:97)
    at org.netbeans.modules.web.core.jsploader.TagLibParseSupport.getTagLibEditorData(TagLibParseSupport.java:67)
    at org.netbeans.modules.web.core.jsploader.TagLibParseSupport.getTagLibEditorData(TagLibParseSupport.java:55)
    at org.netbeans.modules.web.core.syntax.JSPKit.createSyntax(JSPKit.java:94)
    at org.netbeans.editor.BaseDocument.getFreeSyntax(BaseDocument.java:377)
    at org.netbeans.editor.DrawEngine.draw(DrawEngine.java:876)
    at org.netbeans.editor.LeafView.paintAreas(LeafView.java:145)
    at org.netbeans.editor.BaseView.paint(BaseView.java:129)
    at org.netbeans.editor.BaseTextUI$RootView.paint(BaseTextUI.java:594)
    at org.netbeans.editor.BaseTextUI.paintRegion(BaseTextUI.java:238)
    at org.netbeans.editor.EditorUI.paint(EditorUI.java:1315)
    at org.netbeans.editor.BaseTextUI.paint(BaseTextUI.java:217)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:39)
    at javax.swing.JComponent.paintComponent(JComponent.java:395)
    at javax.swing.JComponent.paint(JComponent.java:687)
    at javax.swing.JComponent.paintChildren(JComponent.java:498)
    at javax.swing.JComponent.paint(JComponent.java:696)
    at javax.swing.JViewport.paint(JViewport.java:668)
    at javax.swing.JComponent.paintChildren(JComponent.java:498)
    at javax.swing.JComponent.paint(JComponent.java:696)
    at javax.swing.JComponent.paintChildren(JComponent.java:498)
    at javax.swing.JComponent.paint(JComponent.java:696)
    at javax.swing.JComponent.paintChildren(JComponent.java:498)
    at javax.swing.JComponent.paint(JComponent.java:696)
    at javax.swing.JComponent.paintChildren(JComponent.java:498)
    at javax.swing.JComponent.paint(JComponent.java:696)
    at javax.swing.JComponent.paintChildren(JComponent.java:498)
    at javax.swing.JComponent.paint(JComponent.java:696)
    at javax.swing.JComponent.paintWithBuffer(JComponent.java:3878)
    at javax.swing.JComponent._paintImmediately(JComponent.java:3821)
    at javax.swing.JComponent.paintImmediately(JComponent.java:3672)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:370)
    at org.netbeans.core.windows.frames.PinRepaintRM.paintDirtyRegions(PinRepaintRM.java:75)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:124)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:154)
    [catch] at java.awt.EventQueue.dispatchEvent(EventQueue.java:337)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
    Tue Nov 06 11:35:29 CET 2001: java.lang.NoSuchMethodError: null
    java.lang.NoSuchMethodError
    at org.netbeans.modules.web.core.jsploader.TagLibParseSupport.parsePage(TagLibParseSupport.java:150)
    at org.netbeans.modules.web.core.jsploader.TagLibParseSupport.access$200(TagLibParseSupport.java:41)
    at org.netbeans.modules.web.core.jsploader.TagLibParseSupport$ParsingRunnable.run(TagLibParseSupport.java:119)
    at org.openide.util.Task.run(Task.java:124)
    [catch] at org.openide.util.RequestProcessor$ProcessorThread.run(RequestProcessor.java:626)
    I seems that it can't compile my jsp to servlet
    THX

    ive ran into many problems with compiling in forte. I just compile everything from the command line now, lets me know exactly what switches i want, and it works! ive never seen an error like that in forte though, i would just recommend compiling it from the command line with "javac"...

  • EP,ESS/MSS  and webdynpro for java interview questions.

    I am an ep and ESS?MSS consultant and work on webdynpro for java.I have also worked on PDK like customization of masthead and logon page.I would like to know how to prepare for an interview? I mean what should I read ? and what topics should I cover?

    HI Anzar
    Instead of posting this here, you could have googled it. There are no. of sites for the same thing.
    Since you wrote, so just curious... EP & ESS/MSS Consultant... what does that mean?
    If I am not taking it wrong, by that sentence you are trying to tell that you have worked on ESS / MSS modeule. Right?
    See, if you are an EP Consultant, you must know all the below atleast -
    1. PORTAL SIDE
    a. Different types of iView configuration
    b. User Management
    c. Internal / External Portal Configuration
    d. Content development
    e. UWL
    f. Portal bottlenecks (I mean portal related issues, like slow responding etc.)
    g. Display & Desktop Configuration
    h. System Landscape Directory
    i. NWDI
    2. WEB DYNPRO SIDE
    a. Calling iviews from wd applications
    b. RFC/ BAPI calls
    c. JCO Connections
    d. SC/DC Concept
    e. Import/Export Parameters
    f. Scenario Based Answering (like... if your imported BAPI import parameters are changed by BASIS, what will you do to make it work for you.... etc)
    g. Singleton/Non-Singleton nodes
    h. Controllers
    i. Interfaces
    j. Multi-lingual Applications
    k. EJBs
    l. PDK applications
    This is the basic list, it can contain many more items... This is the list which I faced for my interview. As an EP consultant, you must be good in both Portal as well as WD end.
    1 more thing, every interview is different from other, so no point in just mugging them out. Go through with there concepts. That way, you can answer twisted & scenario based questions.
    Hope this will help.
    Best Regards
    Chander Kararia
    if question solved, close the thread after marking it answered.
    Best Regards
    Chander Kararia

  • Forte(for java) CE question

    Hello people!
    (I found no forum on Forte for java, so I ask my question here)
    Here is it. How can I make Forte know my packages, and support dot notation? ie, say I have a mypack.myotherpack.SomeClass class. When I type
    import mypack.
    at this point it should show what subpackages are available in mypack.
    And if
    SomeClass instance = new ...;
    instance.
    here it should show methods, fields.... But Forte shows all these only in packages and classes that "it already knows" somehow. Does anybody how this is done? It is very frustrating that it does not happen. Thx!

    What class is not found?

  • Java Swing frame for modification Excel file or Word file with All menu...

    Hello All,
    Can Any one help me for making java Swing frame for modification Excel Data or word file with all Menu.. Plz send me java Code for that.. I am bit new in Swing.
    i am waiting for ur help..
    Thanks
    Samir

    hi pbrockway2 ,
    Can you go through this program Sir, i am trying to call Excel content below of menu. when i will press Edit button then excel content should come below with Cut, copy, paste , Save Button..
    Plz help me sir...
    import javax.swing.*;
    import java.io.*;
    import java.awt.event.*;
    public class TestReader
    private static void createAndShowUI()
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame=new JFrame("Test Reader");
    JButton button=new JButton("Edit");
    button.addActionListener(new ButtonListener());
    frame.getContentPane().add(button);
    frame.setVisible(true);
    frame.pack();
    static class ButtonListener implements ActionListener
    public void actionPerformed(ActionEvent event)
    openTheFile();
    private static void openTheFile()
    try
    String commands[]=new String[3];
    commands[0]="cmd.exe";
    commands[1]="/C";
    commands[2]="INSTALL.LOG"; // here file name is supposed to be in the working dir
    Runtime rt=Runtime.getRuntime();
    Process proc=rt.exec(commands);
    StreamGobbler errorGobbler=new StreamGobbler(proc.getErrorStream(),"ERROR");
    StreamGobbler outputGobbler=new StreamGobbler(proc.getInputStream(),"OUTPUT");
    errorGobbler.start();
    outputGobbler.start();
    catch (Exception e){}
    public static void main(String args[])
    SwingUtilities.invokeLater(new Runnable()
         public void run()
         createAndShowUI();
    static class StreamGobbler extends Thread
    InputStream is;
    String type,root;
    StreamGobbler(InputStream is,String type)
    this.is=is;
    this.type=type;
    public void run()
    try
    InputStreamReader isr=new InputStreamReader(is);
         BufferedReader breader=new BufferedReader(isr);
         String line=null;
         while ((line=breader.readLine())!=null)
         System.out.println(type+">"+line);
    catch (Exception e)
         System.out.println(e);
    Thanks
    SamiR

  • Where can I downlaod java swing library for JDk?

    where can I downlaod java swing library for JDk?

    Are you sure you don't have Swing? It comes with the JDK. If you don't have it, look at http://java.sun.com/products/jfc/download.html
    If you are using JDK 1.1, you can download Swing alone - but be aware that this is an old version. You would be best advised to download the Java SDK 1.3.1, which includes Swing 1.1.
    Regards,
    Matt

Maybe you are looking for