• Home
  • Blog
  • Solve using extend javaframe and without for loops… read extra comments below

Solve using extend javaframe and without for loops… read extra comments below

0 comments

please solve this problem without using nested for loops, and please make sure that it’s done including extend JFRAME….

an example of how it would be done is here below…. there are two files that are created to run this code. one is Main.java and the other file is NumbersGui.java.. please do it in a similar manner….

file name :

Main.java

public class Main {

public static void main(String[]args) {

NumbersGUI MyGUI=new NumbersGUI();

MyGUI.display();

}

}

File name: NumberGui.java

import javax.swing.*;

import java.awt.*;

class NumbersGUI extends JFrame{

final int h= 500 , w= 500;

public NumbersGUI(){

setTitle(“GUI”);

setSize(h,w);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(new GridLayout(3,3));

setLocation(100,100);

setVisible(true); }

public void display(){

Container myContent= getContentPane(); //make contentpane

TextArea A2 = new TextArea();

myContent.add(A2);

TextArea A3 = new TextArea();

myContent.add(A3);

TextArea A4 = new TextArea();

myContent.add(A4);

TextArea A5 = new TextArea();

myContent.add(A5);

TextArea A6 = new TextArea();

myContent.add(A6);

TextArea A7 = new TextArea();

myContent.add(A7);

TextArea A8 = new TextArea();

myContent.add(A8);

TextArea A9 = new TextArea();

myContent.add(A9);

TextArea A10 = new TextArea();

myContent.add(A10); //create cells to display numbers

for(int j=1;j<=100;j++) {

if(j%2 == 0)

A2.append(” “+ j + “rn”);

if(j%3 == 0)

A3.append(” “+ j+ “rn”);

if(j%4 == 0)

A4.append(” “+ j+ “rn”);

if(j%5 == 0)

A5.append(” “+ j+ “rn”);

if(j%6 == 0)

A6.append(” “+ j+ “rn”);

if(j%7 == 0)

A7.append(” “+ j+ “rn”);

if(j%8 == 0)

A8.append(” “+ j+ “rn”);

if(j%9 == 0)

A9.append(” “+ j+ “rn”);

if(j%10 == 0)

A10.append(” “+ j + “rn”); }{

setVisible(true);

}

}

}

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}