最小化/最大化JAVA GUI后,框架变黑

时间:2015-09-09 11:33:46

标签: java swing jscrollpane

每当我最小化JFrame时,一切都变黑了。 我也无法向面板添加JScrollPane。 我知道我做错了。 我搜索互联网,我很困惑。 请帮我解决这两个问题。 抱歉英语不好 这是我的代码,我只是粘贴我编写的GUI代码。

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.util.StringTokenizer;
import java.util.Scanner;

class x1 extends JFrame // implements FocusListener
{
    static x1 o1;
    JLabel l1[];
    int z = 0, i = 0, k = 0, l = 0, m = 0, n = 0, mm = 0, rr = 0, inc = 0;
    static int x = 100, sum = 0, summ = 0;
    String s[][], s1[][];
    String s2 = "";
    String base[] = new String[200];
    String derived[] = new String[20];
    JScrollPane scrollPane;
    JPanel topPanel;
    static int yy = 50;
    String copy = new String("");
    String xx[] = new String[1000];
    int count = 0, j = 0, jj = 0, count1 = 0, count2 = 0, level = 1, r = 0, large = 0;
    int size[] = new int[20];

    x1(String aa[]) {

        s = new String[100][3];
        topPanel = new JPanel();
        System.out.println("YYYYYYYYYYYYYYYY : " + yy);
        topPanel.setSize(800, 800);
        topPanel.setLayout(new BorderLayout());

        scrollPane = new JScrollPane();
        getContentPane().add(scrollPane, BorderLayout.CENTER);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    public void get(String ab[]) {

        int i = 0;
        System.out.println("THIS IS GET METHOD");
        while (ab[i] != null) {

            xx[i] = ab[i];
            count++;
            i++;
        }

        // yy=0;

    }

    public void paint(Graphics g) {
        // Graphics2D g2 = (Graphics2D) g;

        System.out.println("COUNT : " + count);
        while (xx[j] != null) {
            if ((xx[j].equals("class")) && (!xx[j + 2].equals("extends"))) {

                if (count1 > 0) {
                    yy = yy - (20 * count1);
                    count1 = 0;
                }
                x = x + 300;

                // g.setColor(Color.PINK);
                g.drawRect(x, yy, 50, 20);

                j++;
                base[k] = xx[j];
                k++;
                s[z][0] = xx[j];
                s[z][1] = String.valueOf(x + 10);
                s[z][2] = String.valueOf(yy + 15);

                // g.setColor(Color.BLACK);
                g.drawString(String.valueOf(s[z][0]), Integer.parseInt(s[z][1]), Integer.parseInt(s[z][2]));

                j = j + 2;

                while (!xx[j].equals("-----")) {

                    if (xx[j].equals("(")) {
                        s2 = s2 + "(";
                        yy = yy + 20;
                        count1++;
                        size[r] = yy;

                    } else if ((xx[j].equals("void")) || (xx[j].equals("int")) || (xx[j].equals("char")) || (xx[j].equals("float")) || (xx[j].equals("double")) || (xx[j].equals("byte"))
                            || (xx[j].equals("short")) || (xx[j].equals("long")) || (xx[j].equals("boolean")) || (xx[j].equals("String"))) {
                        s2 = s2 + xx[j] + " ";
                    } else if (xx[j].equals(")")) {
                        s2 = s2 + ")";
                        int n = s2.length();
                        g.drawRect(x, yy, 200, 20);
                        s[z][1] = String.valueOf(x + 10);
                        s[z][2] = String.valueOf(yy + 15);

                        g.drawString(s2, Integer.parseInt(s[z][1]), Integer.parseInt(s[z][2]));

                        s2 = "";// yy=yy+20;

                    } else {
                        s2 = s2 + xx[j];
                    }
                    j++;
                    // }

                }
                r++;
                z++;

            } // if of class and not extends
            else if ((xx[j].equals("class")) && (xx[j + 2].equals("extends")))

            {
                derived[l] = xx[j + 1];
                System.out.println("DERIVED : " + derived[l]);
                l++;
            }
            rr = 0;
            while (rr < r) {
                if ((r == 1)) {
                    large = size[rr];
                    break;
                }
                /*
                 * if((size[rr+1])==null) {break;}
                 */
                if (size[rr] < size[rr + 1]) {
                    large = size[rr + 1];
                }
                rr++;
            }

            if (j == (count - 1)) {
                derived[l] = "!";
                x = 0;
                while (base[x] != null) {
                    summ++;
                    x++;
                }
                break;
            }
            j++;
        }
        x = 100;
        while (base[m] != null) {
            mm = m;
            yy = large + 50;
            x = 400;
            while (mm < summ) {

                count1 = 0;
                sum = 0;

                jj = 0;
                while (derived[jj] != "!") {

                    if (count1 > 0) {
                        yy = yy - (20 * count1);
                        count1 = 0;
                    }
                    if (derived[jj].equals("0")) {

                    } else {
                        n = 0;
                        while (xx[n] != null) {
                            if ((xx[n].equals("class")) && (xx[n + 1].equals(derived[jj]))) {
                                break;
                            } else
                                n++;
                        }
                        if (xx[n + 3].equals(base[mm])) {

                            copy = copy + derived[jj] + " ";
                            System.out.println("COPY :" + copy + " " + inc);
                            derived[jj] = "0";

                            /*
                             * if(mm>m) {sum=1;}
                             */
                            x = 400;
                            for (int h = 0; h < inc; h++)

                            {
                                x = x + 300;
                            }

                            /*
                             * for(int h=0;h<sum;h++) {x=x+300;}
                             */
                            // g.setColor(Color.PINK);
                            g.drawRect(x, yy, 50, 20);

                            s[z][0] = xx[n + 1];
                            s[z][1] = String.valueOf(x + 10);
                            s[z][2] = String.valueOf(yy + 15);

                            // g.setColor(Color.BLACK);
                            g.drawString(String.valueOf(s[z][0]), Integer.parseInt(s[z][1]), Integer.parseInt(s[z][2]));
                            z++;
                            inc++;
                            while (!xx[n].equals("functions")) {
                                n++;
                            }
                            n++;

                            while (!xx[n].equals("-----")) {

                                if (xx[n].equals("(")) {
                                    s2 = s2 + "(";
                                    yy = yy + 20;
                                    count1++;
                                    count2++;
                                    size[r] = yy;

                                } else if ((xx[n].equals("void")) || (xx[n].equals("int")) || (xx[n].equals("char")) || (xx[n].equals("float")) || (xx[n].equals("double")) || (xx[n].equals("byte"))
                                        || (xx[n].equals("short")) || (xx[n].equals("long")) || (xx[n].equals("boolean")) || (xx[n].equals("String"))) {
                                    s2 = s2 + xx[n] + " ";
                                } else if (xx[n].equals(")")) {
                                    s2 = s2 + ")";
                                    int n = s2.length();
                                    g.drawRect(x, yy, 200, 20);
                                    s[z][1] = String.valueOf(x + 10);
                                    s[z][2] = String.valueOf(yy + 15);

                                    g.drawString(s2, Integer.parseInt(s[z][1]), Integer.parseInt(s[z][2]));
                                    z++;
                                    s2 = "";// yy=yy+20;

                                } else {
                                    s2 = s2 + xx[n];
                                }

                                n++;

                            } // while
                            r++;
                            z++;

                        } // if over
                    } // else
                    jj++;

                }

                rr = 0;
                while (rr < r) {
                    if ((r == 1)) {
                        large = size[rr];
                        break;
                    }
                    /*
                     * if((size[rr+1])==null) {break;}
                     */
                    if (size[rr] < size[rr + 1]) {
                        large = size[rr + 1];
                    }
                    rr++;
                }

                mm++;
            }
            inc = 0;
            StringTokenizer st = new StringTokenizer(copy, " ");

            while (st.hasMoreTokens()) {
                base[k] = st.nextToken();
                k++;
            }

            level++;
            int b = summ;
            while (base[b] != null) {
                summ++;
                b++;
            }
            m = mm - 1;

            m++;
        }

    }

    public static void main(String aa[]) {

        o1 = new x1(aa);

        o1.get(aa);
        o1.setTitle("PROJECT FILE");
        o1.setSize(1600, 900);
        // o1.setResizable(false);
        o1.setVisible(true);
        // o1.pack();
        // o1.setExtendedState(JFrame.MAXIMIZED_BOTH);
        // o1.setUndecorated(true);

    }

}

请忽略所有变量,数组。 最小化和JScrollpane是我的问题,逻辑正在工作但完全停电。

0 个答案:

没有答案