Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: JFRAME PARAMETERS NOT GETTING used in DISPLAY

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JFRAME PARAMETERS NOT GETTING used in DISPLAY

    The frame displayed is not using the parameters and buttons mentioned. Help me to resolve the issue.



    package MyEmployeePackage.MyUtilityPackage;

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    public class myUtilityClass{

    public static void main(){
    myFirstPage mypage=new myFirstPage();
    mypage.displayMyFirstPage();
    mypage.frm1.setVisible(true);
    }
    }
    class myFirstPage {
    myFrame frm1;
    myButton btnEmployee,btnDepartment,btnRegulation,btnEmploye eResponse,btnExit;

    myFirstPage(){
    frm1= new myFrame();
    //frm.setSize(400,500);
    }
    void displayMyFirstPage(){

    btnEmployee = new myButton("Employee");
    frm1.addButton(btnEmployee);

    }

    }
    class myFrame extends JFrame{
    private JFrame frm;
    private JPanel pnl;
    myFrame (){
    frm = new JFrame();
    pnl =new JPanel();
    frm.setSize(500,400);
    frm.setLocation(400,200);
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
    frm.add(pnl);

    }
    void addButton(JButton btn){


    pnl.add(btn);
    }
    }

    class myButton extends JButton{
    JButton btn;
    Color btnColorForegroud;
    Color btnColorBackgroud;
    myButton(String str){
    btn= new JButton(str);
    btnColorForegroud = new Color(79,81,228);
    btnColorBackgroud = new Color(240,221,186);
    btn.setPreferredSize(new Dimension(100,50));
    btn.setForeground(btnColorForegroud);
    btn.setBackground(btnColorBackgroud);
    }

    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,016
    Thanks
    52
    Thanked 2,365 Times in 2,319 Posts

    Default Re: JFRAME PARAMETERS NOT GETTING used in DISPLAY

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Be sure code is properly formatted with indentations to show logical nesting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2019
    Posts
    20
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default Re: JFRAME PARAMETERS NOT GETTING used in DISPLAY

    1. class name first letter uppercase
    2. remove private JFrame frm; becasue class myFrame extends JFrame

    package com.tool.util;
     
    import java.awt.Color;
    import java.awt.Dimension;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    public class UtilityClass {
     
        public static void main(String[] args) {
            MyFirstPage mypage = new MyFirstPage();
            mypage.displayMyFirstPage();
            mypage.frm1.setVisible(true);
        }
    }
     
    class MyFirstPage {
        MyFrame frm1;
        MyButton btnEmployee, btnDepartment, btnRegulation, btnEmploye, eResponse, btnExit;
     
        public MyFirstPage() {
            frm1 = new MyFrame();
            frm1.setSize(400,500); 
        }
     
        void displayMyFirstPage() {
     
            btnEmployee = new MyButton("Employee");
            frm1.addButton(btnEmployee);
     
        }
     
    }
     
    class MyFrame extends JFrame {
        private JPanel pnl;
     
        MyFrame() {
            pnl = new JPanel();
            this.setSize(500, 400);
            this.setLocation(400, 200);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.add(pnl);
     
        }
     
        void addButton(JButton btn) {
     
            pnl.add(btn);
        }
    }
     
    class MyButton extends JButton {
        JButton btn;
        Color btnColorForegroud;
        Color btnColorBackgroud;
     
        MyButton(String str) {
            btn = new JButton(str);
            btnColorForegroud = new Color(79, 81, 228);
            btnColorBackgroud = new Color(240, 221, 186);
            btn.setPreferredSize(new Dimension(100, 50));
            btn.setForeground(btnColorForegroud);
            btn.setBackground(btnColorBackgroud);
        }
     
    }

  4. #4
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    281
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: JFRAME PARAMETERS NOT GETTING used in DISPLAY

    Extending JFrame is not a good practice. Just make an instance of it and use that. If you're going to paint, then extend JPanel and override paintComponent(Graphics g). And add the JPanel to your JFrame instance.

    Regards,
    Jim

Similar Threads

  1. How Do I Display A World Into A JFrame?
    By _vertig0 in forum Java Rendering and Gaming
    Replies: 0
    Last Post: December 31st, 2017, 12:51 AM
  2. Rectangle won't display in JFrame
    By SquidGiant in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 30th, 2014, 03:45 PM
  3. Image display problem on JFrame...Whats wrong......need help?????'
    By suyog53 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 12th, 2012, 12:06 PM
  4. Image display problem on JFrame...Can any1 help?????'
    By suyog53 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 21st, 2012, 09:26 AM
  5. How to display a Rectangle object in JFrame (Problem).
    By voltaire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 15th, 2012, 07:22 PM

Tags for this Thread