Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m supposed to make a program with 2 sorting algorithms. Everything works fine

ID: 3604151 • Letter: I

Question

I'm supposed to make a program with 2 sorting algorithms. Everything works fine for the most part but my problem now is that I need them both to display at the same time on 1 JFrame and I can't get it to work no matter what I do.

Here's where the problem is:

import javax.swing.*;
import java.awt.*;
public class AlgorithmViewer {
public static void main(String[] args){
  AlgorithmViewer av=new AlgorithmViewer();
}
public void Gui(){
  JFrame frame=new JFrame();
  JPanel panel=new JPanel();
  JPanel panel2=new JPanel();
  frame.setSize(800,800);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  final SelectionSortComponent component=new SelectionSortComponent();
  final BubbleSortComponent component2=new BubbleSortComponent();
  frame.add(panel);
  frame.add(panel2);
  panel.add(component);
  panel2.add(component2);
  frame.setVisible(true);
  component.animation();
  component2.animation();
}
public AlgorithmViewer(){
  Gui();
}
}
I've tried to do multiple layouts and none of them worked for me so I would like to know what to do about this.

Explanation / Answer

import javax.swing.*;
import java.awt.*;
public class AlgorithmViewer {
public static void main(String[] args){
  AlgorithmViewer av=new AlgorithmViewer();
}
public void Gui(){
  JFrame frame=new JFrame();
  JPanel panel=new JPanel();
  JPanel panel2=new JPanel();
  frame.setSize(800,800);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  final SelectionSortComponent component=new SelectionSortComponent();
  final BubbleSortComponent component2=new BubbleSortComponent();
  frame.add(panel);
  frame.add(panel2);
  panel.add(component);
  panel2.add(component2);
  frame.setVisible(true);
  component.animation();
  component2.animation();
}
public AlgorithmViewer(){
  Gui();
}
}