Note that there are some explanatory texts on larger screens.

plurals
  1. POJava JComponent paint --Almost working
    primarykey
    data
    text
    <p>I almost have the repaint() Jcomponent working. I had it working and then tried to make an absolute positioning and now it doesn't work.</p> <pre><code>import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; public class DDHGenericFrame { private static final long serialVersionUID = 1L; DDHGenericPanel d = new DDHGenericPanel(); //DDHCircleOne o = new DDHCircleOne(); public DDHGenericFrame() { initUI(); } public final void initUI() { JFrame frame = new JFrame("AbsoluteLayoutDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("Draw Circle"); frame.setBackground(Color.green); frame.setLayout(null); frame.setSize(300,425); frame.add(d); // frame.add(o);//didn't work neither frame.setVisible(true); } public static void main(String[] args) { DDHGenericFrame ex = new DDHGenericFrame(); } } </code></pre> <p>Class 2: (This is the JComponent that I am trying to set)</p> <pre><code>import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JComponent; public class DDHTestDraw extends JComponent { public DDHTestDraw () { settPreferredSize(); } public void settPreferredSize() { Dimension d = new Dimension(25,25); setPreferredSize(d); } protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawString("Text",20,20); } } </code></pre> <p>I added my component to the Container and then added the container to the JPanel and then the JPanel is added to the JFrame. I would think that this should work. I have a set preferred size. I had it working once and now it doesn't work.</p> <p>I want to be able to make a component that is a circle. I want that circle to be able to be drawn any where on a Jframe, and then I want that circle to be able to move based on a a certain length of time. I am going to make a game that has circles dropping from the top and then falling to the bottom. When I had it working I did have the circle being written to the JPanel which is a complex piece of code. But I have had to go back to the old simple method of writing a single graphical word.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload