#idk what to do tbh

16 messages · Page 1 of 1 (latest)

wide oriole
#

The third text frame behaves weird

    public static void main(String[] args) {

        String name = JOptionPane.showInputDialog("Enter Your Name");
        JOptionPane.showMessageDialog(null,"Hello "+name);

        int age = Integer.parseInt(JOptionPane.showInputDialog("Enter Your Age"));
        JOptionPane.showMessageDialog(null,"You are "+age+" years old");

        double height = Double.parseDouble(JOptionPane.showInputDialog("Enter Your Height in cm"));
        JOptionPane.showMessageDialog(null,"You are "+height+" cm tall");

        String heightstr = ""+height;
        String agestr = ""+age;
        double born = 2023-age;
        String bornstr = " "+ born;

        Font font = new Font("Franklin Gothic",Font.BOLD,30);

        JFrame f = new JFrame();
        f.setBounds(600,500,400,400);

        JTextField tfn = new JTextField("name");
        tfn.setEditable(false);
        tfn.setText(name);
        tfn.setHorizontalAlignment(SwingConstants.LEFT);
        tfn.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        tfn.setFocusable(false);
        tfn.setFont(font);
        tfn.setBounds(10,50,300,50);

        JTextField tfa = new JTextField("age");
        tfa.setEditable(false);
        tfa.setText(agestr);
        tfa.setHorizontalAlignment(SwingConstants.LEFT);
        tfa.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        tfa.setFocusable(false);
        tfa.setFont(font);
        tfa.setBounds(10,125,300,50);

        JTextField tfh = new JTextField("height");
        tfh.setEditable(false);
        tfh.setText(heightstr);
        tfh.setHorizontalAlignment(SwingConstants.LEFT);
        tfh.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        tfh.setFont(font);
        tfh.setFocusable(false);
        tfh.setBounds(10,200,300,50);

        f.add(tfn);
        f.add(tfa);
        f.add(tfh);

        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        f.setVisible(true);



    }
}```
wind oakBOT
#

This post has been reserved for your question.

Hey @wide oriole! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

fringe saffron
#

So I tried this code, then what I know works.
To sum up: Java Swing really doesn't accept that you don't follow the guidelines

#

It is true about all GUI frameworks to a point, but Java Swing just won't accept things that sounds intuitive at first glance

#

So: follow a Java Swing tutorial

#

Do not, ever, think you're allowed to do differently. Not if you use Swing, you aren't

#

(And technically other GUI frameworks aren't more lenient, beside the ones based on HTML. It's just the others, at least, make it so a first intuitive try is within guidelines)

gusty notch
#

.setResizeable() method can be used

wide oriole
#

cool

fringe saffron
#

I hear you've been supposed to use JavaFX instead for a decade or so

#

Never took the time to try and learn, I rarely use GUIs other than in a browser

solemn cosmos
#

as you set bounds manually, to solve your problem, you just need to set layout as null f.setLayout(null);

#

but consider Kyo's messages about javafx and following guides strictly