How can I change size rect in JPanel from another JPanel?

I have code:
import java.awt.*;
import javax.swing.*;
public class ProgramD {
public static void main(String[] arg) {
JFrame f=new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(840,440);
f.setLayout(null);
PanelLeft p1=new PanelLeft();
p1.setSize(400,400);
p1.setLocation(0,0);
f.add(p1);
PanelRight p2=new PanelRight();
p2.setSize(400,400);
p2.setLocation(400,0);
f.add(p2);
f.setVisible(true);
class PanelLeft extends JPanel {
Shape shape1;
PanelLeft() {
shape1=new Rectangle(30,30,100,50);
public void paintComponent(Graphics g) {
Graphics2D g2=(Graphics2D) g;
g2.setColor(Color.red);
g2.fill(shape1);
class PanelRight extends JPanel {
PanelRight() {
setBackground(Color.green);
JTextField field1=new JTextField(4);
JTextField field2=new JTextField(4);
JButton b=new JButton("resize");
add(field1);
add(field2);
add(b);
}I would like to wrote width and height size of rect and click resize button, rect must change its size. I may add ActionListener, but I don't know what I may get size from PanelLeft and set size to PanelLeft. How may I solve this problem?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ProgramDada{
  public static void main(String[] arg) {
    JFrame f=new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container con = f.getContentPane();
    con.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    PanelLeft p1 = new PanelLeft();
    p1.setPreferredSize(new Dimension(400, 400));
    gbc.gridx = 0;
    gbc.gridy = 0;
    con.add(p1, gbc);
    PanelRight p2 = new PanelRight(p1);
    p2.setPreferredSize(new Dimension(400,400));
    gbc.gridx = 1;
    con.add(p2, gbc);
    f.pack();
    f.setVisible(true);
class PanelLeft extends JPanel {
  int x, y, w, h;
  Shape shape1;
  PanelLeft() {
    x = 30;
    y = 30;
    w = 100;
    h = 50;
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2=(Graphics2D) g;
    shape1 = new Rectangle(x, y, w, h);
    g2.setColor(Color.red);
    g2.fill(shape1);
class PanelRight extends JPanel implements ActionListener{
  PanelLeft pt;
  JTextField field1, field2;
  JButton b;
  PanelRight(PanelLeft p) {
    pt = p;
    setBackground(Color.green);
    field1 = new JTextField(4);
    field2 = new JTextField(4);
    b = new JButton("resize");
    add(field1);
    add(field2);
    add(b);
    b.addActionListener(this);
  public void actionPerformed(ActionEvent e){
    pt.w = Integer.parseInt(field1.getText());
    pt.h = Integer.parseInt(field2.getText());
    pt.repaint();
}

Similar Messages

  • How can I change I tune into English from another language?

    My itune is set in Korean.  I want to change that to Enlish.  How do I do that?

    Take a look here:
    iTunes: Changing the display language
    Regards.

  • Mail -- How can I change the default email account from which my messages go, without having to change it each time I draft a message?  It currently assumes an email account that I rarely use. Thanks.

    How can I change the default email account from which my messages go, without having to change it each time I draft a message?  It currently assumes an email account that I rarely use. Thanks.

    sorry, but I can't find the mail preference in the latest Yosemite OS. Do you know where I can find it?
    Thank you
    Don

  • How can I change my auto-correction language from english to french?

    My system language is english, so all the default language is also in english
    but how can I change the auto-correction language from english to french and without changing the menu language?
    Message was edited by: Marixomia

    It's just, I want to change my spelling checker from english to french, that when I type some words in wrong order or miss some, I can know that.
    For now, when I type in french, almost every words are underlined by the red lines...

  • How can i change a pdf file type to another file type

    how can i change a pdf file type to another file type

    You can copy the contents and paste it into a Word file. Just don't expect everything to transfer or to retain all of the formatting.

  • How can I change the default pdf reader from the installed (but not yet registered) Adobe Acrobat 9 Pro to Adobe Reader XI?

    How can I change the default pdf reader from the installed (but not yet registered) Adobe Acrobat 9 Pro to Adobe Reader XI? I'm having some hiccups getting Adobe to register the software, but since I set it as the default .pdf reader during setup, things try (and fail) to open in the as yet unregistered software. How can I change it temporariiy to the Acrobat Reader XI that I have installed?

    Anubha,
    It worked! Thank you so much.
    I'd opened file with the 'Open with' feature then clicking Adobe Reader,
    but that didn't do it. When I used 'Open with', then 'Choose default
    program...', it worked like a charm.
    Again, thank you!
    Jonathan
    On Wed, Mar 18, 2015 at 10:16 PM, Anubha Goel <[email protected]>

  • How can I change the formate of @today from (MM/dd/yyy) to (dd-MM-yyyy)?

    I am in openscript, using a settext commend - .setText("{{@today(MM/dd/yyyy), 10-02-2011}}}}"); is anyone know how can I change the formate of @today from (MM/dd/yyy) to (dd-MM-yyyy)?
    I went to Java Code tab and tried to use - new SimpleDataFormat("dd-MM-yyyy").format(new Date()); but not successful. Any help will be appreciated.
    Katherine

    Hi,
    you can display the date format in dd-mm-yy by using the below Java code.
    First import the bellow java classes.
    import java.util.Date;
    import java.text.SimpleDateFormat;
    //and add bellow code in run() function
         //************ Display Date and Time *************
         Date date_format=new Date();
         SimpleDateFormat dateFormat = new SimpleDateFormat("dd-mm-yyyy");// HH:mm:ss");
         String Exec_Time = dateFormat.format(date_format);
    //output statement
    info("Today's Date: "+Exec_Time);
    I can able to add the screenshot of this output here, so if you need any other information please write to me.
    Regards,
    MRSN

  • Hello! How can I change language of IndesignCC menus from russian into english after installation?

    Hello! How can I change language of IndesignCC menus from russian into english after installation?

    i don't think you can.
    uninstall id, open your cc desktop app>click settings (the gear icon)>preferences>apps>app language>english>reinstall id

  • HT1311 How can i change my ID to US from UK !?

    How can i change my ID to US from UK !? When i have 0.15 Pounds left ? Can i clear it ?

    You will need to try contacting iTunes Support and ask if they can remove the balance for you so that you can change country : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • How can I change my computer's language from English to Spanish?

    How can I change my computer's language from English to Spanish? My computer is an iMac G3 (CRT) and it has Mac OS 9 installed.

    This isn't possible in Mac OS 9.2.2 and earlier without doing a full installation of the Spanish version of the OS, which requires an installation disk containing it.
    (65772)

  • How can I change the default templates to from A4 to Letter US?

    Hi,
    I live in Québec, the french part of Canada. Because I use French, iWork think I leave in France, so the default templates are in A4.
    How can I change the default templates to from A4 to Letter US? It seem's impossible. In Pages 06, each language folder had templates. But with Pages 08, it's different.
    Please help.

    Autre façon : Ouvre un nouveau document. Il va être en A4. Dans le menu Fichier--->Format d'impression. Une fenêtre apparaît. Dans la ligne... Taille du papier, tu choisis... Lettre US; tu fais OK. Ensuite tu sauves ce document comme modèle. Menu Fichier----> Enregistrer comme modèle et tu lui donnes le nom, par exemple... USLettre.
    Ensuite, va dans le menu Pages, va dans préférences et dans la fenêtre qui s'ouvre - Préférences générales - tu choisis : Utiliser le modèle... et tu cliques sur Choisir... à droite un peu en bas de Utiliser le.... et là, dans la fenêtre qui va apparaître, tu trouves le modèle que tu viens de faire...USLettre.
    Voilà. Chaque fois que tu vas ouvrir Pages, ce sera USLettre qui sera là par défaut.
    J'espère que ça va te satisfaire.
    Évidemment l'idéal serait de pouvoir changer la template Vierge par une template Vierge US... mais j'ai pas encore réussi.
    Message was edited by: BenwaR

  • How can I change email received by others from me via my IMac and MacBookPro being received as APPLE?ring as just Apple

    How can I change emails received by others from me on my IMac and MacBookPro appearing on their computers as 'APPLE' and not my name?

    Thanks - I did not realize that Homesharing can be specifically set to a photo destination like that!
    So, it would appear that I can either point it to iPhoto (and folders/ events within that) OR the default Pictures folder and subfolders of that OR any other specific folder (and subfolders of that) of my choice.  However, I cannot select BOTH the default Pictures folder (and some subfolder of that) AND a folder in iPhoto AND/ OR an event/ folder in iPhoto.  Is that a correct assumption?
    If so, the only way I see getting homesharing to get both set of pictures is to get all my picture folders (internal and external drive based) into iPhoto (without physically duplicating them) - and then pointing Homesharing to iPhoto, right?
    I think you have solved my issue - but I just want to be sure of that.
    Thanks a ton!

  • How can I change my internal airport card from G to N ???

    I just want to know how can I change my internal airport card from G to N and how much that cost ?

    Robertito wrote:
    I just want to know how can I change my internal airport card from G to N and how much that cost ?
    The description of your machine (2 ghz MacBook) can describe maybe three different generations of the original polycarbonate MacBook.
    If your machine is a Core 2 Duo MacBook that came out before the late 2007 models - $2.49 Canadian. It's all done in software, and won't work on the Core Duo models. The equivalent enabling software also comes on a disc if you get the latest 802.11n Apple AirPort Extreme or AirPort Express base stations.
    http://store.apple.com/ca/product/D4141ZM/A
    Before you buy, you can check to see if your machine already has it.

  • After upgrading to Photos, how can I work on a Book Project from another apple device?

    After upgrading to Photos, how can I work on a Book Project from another apple device?

    I'm not sure I understand what you are asking, but on the device/Settings, do you have iCloud and Photos sync turned on?

  • My Gf has my iphone. How can I see recent messages and calls from another device?

    My Gf has my iphone. How can I see recent messages and calls from another device?

    Depending on your carrier, you may be able to see recent calls by logging into your account on the carrier's web site, if they offer such a feature, though incoming calls being shown is not usual. There will, as diesel said, be no way to see messages already received, either SMS/MMS or iMessages, without having the phone.
    Regards.

Maybe you are looking for