Results 1 to 3 of 3
  1. #1
    653sandeep is offline Member
    Join Date
    Apr 2014
    Posts
    1
    Rep Power
    0

    Question What is the question here???

    Sorry to interrupt.. But i'm new to this Forum... And i don't know hoe to start a new thread :( :( so i'm just going to post my code here and hope for a kind soul to reply...

    public class pracDraw extends JFrame {
    private Color red=Color.red;
    public int i;
    private Color white = Color.white;
    JPanel pr=new JPanel();
    JTextField t=new JTextField();
    JTextField t1=new JTextField();
    JTextField t2=new JTextField();
    JTextArea ta=new JTextArea();
    pracDraw(){
    setTitle("Practise");
    setSize(500,500);
    setVisible(true);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    add(t);
    add(t1);
    add(pr);

    }
    public void paint(Graphics g){
    g.setColor(Color.BLACK);
    g.drawLine(100, 100, 200, 200);
    Graphics2D g2 = (Graphics2D) g;
    g.setColor(Color.BLUE);
    g.drawLine(200, 200, 350, 375);
    t.setBounds(390, 370, 10, 10);
    t.setBackground(Color.RED);
    t.setEnabled(false);
    Thread t5=new Thread(){
    public void run()
    {
    for(;;){

    int x,y,x1=200,y1=200,x2=400,y2=400,t_x,t_y,slope;
    slope=(y2-y1)/(x2-x1); //slope=1
    int c=(y1-(slope*x1)); //c=0
    for(i=200;i<375;i+=20){
    if(i==(slope*i+c)){

    t1.setBounds(i,i, 10, 10);
    t1.setBackground(Color.RED);
    t1.setEnabled(false);



    }
    try {
    sleep(1000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }


    }


    }
    };

    t5.start();
    if(i>375){
    t5.stop();
    t1.setBackground(Color.GREEN);

    }
    }



    public static void main(String args[]){
    pracDraw p=new pracDraw();

    }
    }


    If u run it you can see that the JTextField (t1) is drawn on the panel along the line but it does so with a gray border. How do i eliminate that grey border and only draw the text field along the line and finally make the text field green after it reaches the end of line?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: What is the question here???

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Posts
    447
    Rep Power
    6

    Default Re: What is the question here???

    Hi,

    I am just wondering: the paint method is called whenever the window must be rewdrawn and that happens quite often e.g. moving or resizing the window or when it was overlapped by some other window.

    And you start a new thread each time? Are you sure that you want to do that?

    Konrad

Similar Threads

  1. Replies: 2
    Last Post: 05-25-2012, 05:00 PM
  2. Java Question [Beginner Question]
    By joker760 in forum New To Java
    Replies: 3
    Last Post: 12-13-2011, 05:01 PM
  3. question posted by indissa: library question.
    By Fubarable in forum New To Java
    Replies: 2
    Last Post: 11-18-2011, 02:14 AM
  4. Question concerning question marks and colons
    By jim01 in forum New To Java
    Replies: 17
    Last Post: 01-14-2011, 01:05 AM
  5. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •