ABC

ABC

package threeDAssignment;

import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

import javax.swing.Box; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel;

@SuppressWarnings("serial") public class LayerOptionDialog extends JDialog implements ActionListener {

public LayerOptionDialog(JFrame owner, String title) {
    super(owner,title);

    setSize(350, 150);

    setLocation(new Point(0, owner.getHeight()-155));

    setResizable(false);

    grid=((DisplayUI)owner).getGrid();

    canvas=((DisplayUI)owner).getCanvas();

    createDialog();

    addListeners();
}

private void addListeners() {
    cmbDirection.addActionListener(this);
    cmbLayer.addActionListener(this);

    btnBack.addActionListener(this);
    btnForward.addActionListener(this);
    btnFastBack.addActionListener(this);
    btnFastForward.addActionListener(this);
    btnStop.addActionListener(this);

    btnReset.addActionListener(this);
    btnClose.addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e) {
    Object source=e.getSource();

    if(source.equals(cmbDirection))
    {
        if(cmbDirection.getSelectedIndex()>0){
            DefaultComboBoxModel cmbLayerModel=(DefaultComboBoxModel)cmbLayer.getModel();
            cmbLayerModel.removeAllElements();

            if(cmbDirection.getSelectedIndex()==1){
                int NX=grid.getNX();
                for(int i=1; i<=NX; i++){
                    cmbLayerModel.addElement(i);
                }
            }else if(cmbDirection.getSelectedIndex()==2){
                int NY=grid.getNY();
                for(int i=1; i<=NY; i++){
                    cmbLayerModel.addElement(i);
                }
            }
            else if(cmbDirection.getSelectedIndex()==3){
                int NZ=grid.getNZ();
                for(int i=1; i<=NZ; i++){
                    cmbLayerModel.addElement(i);
                }
            }

            cmbLayer.repaint();
        }else{
            DefaultComboBoxModel cmbLayerModel=(DefaultComboBoxModel)cmbLayer.getModel();
            cmbLayerModel.removeAllElements();
            cmbLayer.repaint();
        }
    }
    else if(source.equals(cmbLayer)){
        showGridLayer(0);

    }

    else if(source.equals(btnForward)){
        showGridLayer(1);
    }
    else if(source.equals(btnBack)){
        showGridLayer(-1);
    }
    else if (source.equals(btnFastForward)) {
        isStop=false;
        if (cmbDirection.getSelectedIndex() > 0) {
                Thread t = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        while (Integer.parseInt(cmbLayer.getSelectedItem().toString()) < ((cmbDirection.getSelectedIndex()==1)?grid.getNX():((cmbDirection.getSelectedIndex()==2)?grid.getNY():grid.getNZ()))) {
                            if(isStop)
                                return;
                            showGridLayer(1);
                            if(Integer.parseInt(cmbLayer.getSelectedItem().toString()) == ((cmbDirection.getSelectedIndex()==1)?grid.getNX():((cmbDirection.getSelectedIndex()==2)?grid.getNY():grid.getNZ()))){
                                return;
                            }
                            try {
                                Thread.sleep(300);
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                            }
                        }
                    }
                });
                t.start();
        }
    }
    else if (source.equals(btnFastBack)) {
        isStop=false;
        if (cmbDirection.getSelectedIndex() > 0) {
            Thread t = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        while (Integer.parseInt(cmbLayer.getSelectedItem().toString()) > 0) {
                            if(isStop)
                                return;
                            showGridLayer(-1);
                            if(Integer.parseInt(cmbLayer.getSelectedItem().toString())==1)
                                return;
                            try {
                                Thread.sleep(300);
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                            }
                        }
                    }
                });
                t.start();
        }
    }
    else if(source.equals(btnReset)){
        cmbDirection.setSelectedIndex(0);
        DefaultComboBoxModel cmbLayerModel=(DefaultComboBoxModel)cmbLayer.getModel();
        cmbLayerModel.removeAllElements();
        cmbLayer.repaint();
        canvas.showLayer(0);
    }
    else if(source.equals(btnClose)){
        this.dispose();
    }
    else if(source.equals(btnStop)){

// t.interrupt(); isStop=true; } }

private void showGridLayer(int i) {
    if(cmbDirection.getSelectedIndex()>0){
        DefaultComboBoxModel cmbLayerModel=(DefaultComboBoxModel)cmbLayer.getModel();
        if(cmbLayerModel.getSize()>0){
            int layer=Integer.parseInt(cmbLayer.getSelectedItem().toString());
            if(cmbDirection.getSelectedIndex()==1){

                if((layer+i)<=grid.getNX() && (layer+i)>0){
                    canvas.showLayer(layer+i);
                    cmbLayer.setSelectedItem(layer+i);
                }

            }else if(cmbDirection.getSelectedIndex()==2){

                if((layer+i)<=grid.getNY() && (layer+i)>0){
                    canvas.showLayer(grid.getNX()+layer+i);
                    cmbLayer.setSelectedItem(layer+i);
                }
            }else if(cmbDirection.getSelectedIndex()==3){

                if((layer+i)<=grid.getNZ() && (layer+i)>0){
                    canvas.showLayer(grid.getNX()+grid.getNY()+layer+i);
                    cmbLayer.setSelectedItem(layer+i);
                }
            }
        }
    }else{
        canvas.showLayer(0);
    }
}

private void createDialog() {
    setLayout(new GridBagLayout());
    GridBagConstraints gbc=new GridBagConstraints();

    Insets ins=new Insets(10, 2, 10, 2);

    gbc.anchor=GridBagConstraints.FIRST_LINE_START;
    gbc.fill=GridBagConstraints.BOTH;
    gbc.insets=ins;

    gbc.gridx=0;
    gbc.gridy=0;
    add(new JLabel("Direction :"),gbc);

    cmbDirection=new JComboBox(new Object[]{"Select","X-Direction","Y-Directiion","Z-Direction"});
    gbc.gridx=1;
    gbc.gridwidth=2;
    add(cmbDirection,gbc);

    gbc.gridx=2;
    gbc.gridwidth=1;
    add(Box.createHorizontalStrut(10),gbc);

    gbc.gridx=3;
    add(new JLabel("   Layer :"),gbc);

    cmbLayer=new JComboBox();
    gbc.gridx=4;
    add(cmbLayer,gbc);

    btnFastBack=new JButton("<<<");
    gbc.gridx=0;
    gbc.gridy=1;
    add(btnFastBack,gbc);

    btnBack=new JButton("<<");
    gbc.gridx=1;
    add(btnBack,gbc);

    btnStop=new JButton("...");
    gbc.gridx=2;
    add(btnStop,gbc);

    btnForward=new JButton(">>");
    gbc.gridx=3;
    add(btnForward,gbc);

    btnFastForward=new JButton(">>>");
    gbc.gridx=4;
    add(btnFastForward,gbc);

    gbc.gridx=0;
    gbc.gridy=2;
    gbc.gridwidth=2;
    add(Box.createHorizontalStrut(50),gbc);

    btnReset=new JButton("Reset");
    gbc.gridx=1;
    gbc.gridwidth=1;
    add(btnReset,gbc);

    gbc.gridx=2;
    add(Box.createHorizontalStrut(50),gbc);

    btnClose=new JButton("Close");
    gbc.gridx=3;
    add(btnClose,gbc);
}

private Grid grid;
private ThreeDCanvas canvas;

private JComboBox cmbLayer;
private JComboBox cmbDirection;

private JButton btnBack;
private JButton btnForward;
private JButton btnFastBack;
private JButton btnFastForward;
private JButton btnStop;
private JButton btnReset;
private JButton btnClose;

private boolean isStop=false;

}

View Answers









Related Tutorials/Questions & Answers:
ABC
ABC
Advertisements
ModuleNotFoundError: No module named 'hjy_abc'
ModuleNotFoundError: No module named 'hjy_abc'  Hi, My Python..._abc' How to remove the ModuleNotFoundError: No module named 'hjy_abc... to install padas library. You can install hjy_abc python with following command
ModuleNotFoundError: No module named 'micropython-abc'
ModuleNotFoundError: No module named 'micropython-abc'  Hi, My... named 'micropython-abc' How to remove the ModuleNotFoundError: No module named 'micropython-abc' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pycopy-abc'
ModuleNotFoundError: No module named 'pycopy-abc'  Hi, My Python... 'pycopy-abc' How to remove the ModuleNotFoundError: No module named 'pycopy-abc' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'pycopy-abc'
ModuleNotFoundError: No module named 'pycopy-abc'  Hi, My Python... 'pycopy-abc' How to remove the ModuleNotFoundError: No module named 'pycopy-abc' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'recursive-abc'
ModuleNotFoundError: No module named 'recursive-abc'  Hi, My... 'recursive-abc' How to remove the ModuleNotFoundError: No module named 'recursive-abc' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'uek-abc'
ModuleNotFoundError: No module named 'uek-abc'  Hi, My Python...-abc' How to remove the ModuleNotFoundError: No module named 'uek-abc... to install padas library. You can install uek-abc python with following command
ModuleNotFoundError: No module named 'abc_algorithm'
ModuleNotFoundError: No module named 'abc_algorithm'  Hi, My... 'abc_algorithm' How to remove the ModuleNotFoundError: No module named 'abc_algorithm' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'abc-analysis'
ModuleNotFoundError: No module named 'abc-analysis'  Hi, My Python... 'abc-analysis' How to remove the ModuleNotFoundError: No module named 'abc-analysis' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'abc-classroom'
ModuleNotFoundError: No module named 'abc-classroom'  Hi, My... 'abc-classroom' How to remove the ModuleNotFoundError: No module named 'abc-classroom' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'abc-delegation'
ModuleNotFoundError: No module named 'abc-delegation'  Hi, My... named 'abc-delegation' How to remove the ModuleNotFoundError: No module named 'abc-delegation' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'backports_abc'
ModuleNotFoundError: No module named 'backports_abc'  Hi, My... 'backports_abc' How to remove the ModuleNotFoundError: No module named 'backports_abc' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'colorlog-abc'
ModuleNotFoundError: No module named 'colorlog-abc'  Hi, My Python... 'colorlog-abc' How to remove the ModuleNotFoundError: No module named 'colorlog-abc' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'danmu-abc'
ModuleNotFoundError: No module named 'danmu-abc'  Hi, My Python... 'danmu-abc' How to remove the ModuleNotFoundError: No module named 'danmu-abc' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'dataclass-abc'
ModuleNotFoundError: No module named 'dataclass-abc'  Hi, My... 'dataclass-abc' How to remove the ModuleNotFoundError: No module named 'dataclass-abc' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-abc'
ModuleNotFoundError: No module named 'django-abc'  Hi, My Python... 'django-abc' How to remove the ModuleNotFoundError: No module named 'django-abc' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'hjy_abc'
ModuleNotFoundError: No module named 'hjy_abc'  Hi, My Python..._abc' How to remove the ModuleNotFoundError: No module named 'hjy_abc... to install padas library. You can install hjy_abc python with following command
Version of com.rklaehn>abc-collection_2.12 dependency
List of Version of com.rklaehn>abc-collection_2.12 dependency
Version of com.rklaehn>abc-collection_sjs0.6_2.12 dependency
List of Version of com.rklaehn>abc-collection_sjs0.6_2.12 dependency
Version of com.rklaehn>abc-extras_2.12 dependency
List of Version of com.rklaehn>abc-extras_2.12 dependency
Version of com.rklaehn>abc-extras_sjs0.6_2.12 dependency
List of Version of com.rklaehn>abc-extras_sjs0.6_2.12 dependency
Version of com.rklaehn>abc-laws_2.12 dependency
List of Version of com.rklaehn>abc-laws_2.12 dependency
Version of com.rklaehn>abc-laws_sjs0.6_2.12 dependency
List of Version of com.rklaehn>abc-laws_sjs0.6_2.12 dependency
Version of com.rklaehn>abc-collection_2.11 dependency
List of Version of com.rklaehn>abc-collection_2.11 dependency
Version of com.rklaehn>abc-collection_sjs0.6_2.11 dependency
List of Version of com.rklaehn>abc-collection_sjs0.6_2.11 dependency
Version of com.rklaehn>abc-extras_2.11 dependency
List of Version of com.rklaehn>abc-extras_2.11 dependency
Version of com.rklaehn>abc-extras_sjs0.6_2.11 dependency
List of Version of com.rklaehn>abc-extras_sjs0.6_2.11 dependency
Version of com.rklaehn>abc-laws_2.11 dependency
List of Version of com.rklaehn>abc-laws_2.11 dependency
Version of com.rklaehn>abc-laws_sjs0.6_2.11 dependency
List of Version of com.rklaehn>abc-laws_sjs0.6_2.11 dependency
ModuleNotFoundError: No module named 'py-aiger-abc'
ModuleNotFoundError: No module named 'py-aiger-abc'  Hi, My Python... 'py-aiger-abc' How to remove the ModuleNotFoundError: No module named 'py-aiger-abc' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'py-aiger-abc'
ModuleNotFoundError: No module named 'py-aiger-abc'  Hi, My Python... 'py-aiger-abc' How to remove the ModuleNotFoundError: No module named 'py-aiger-abc' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'abc-graphene-sqlalchemy'
ModuleNotFoundError: No module named 'abc-graphene-sqlalchemy'  Hi...: No module named 'abc-graphene-sqlalchemy' How to remove the ModuleNotFoundError: No module named 'abc-graphene-sqlalchemy' error? Thanks   
Maven Dependency abc-collection_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_2.11 version0.2.1 in your project
Maven Dependency abc-collection_2.11 >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_2.11 version0.2.0 in your project
Maven Dependency abc-collection_sjs0.6_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_sjs0.6_2.11 version0.2.1 in your project
Maven Dependency abc-collection_sjs0.6_2.11 >> 0.3.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_sjs0.6_2.11 version0.3.0 in your project
Maven Dependency abc-extras_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_2.11 version0.2.1 in your project
Maven Dependency abc-extras_2.11 >> 0.3.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_2.11 version0.3.0 in your project
Maven Dependency abc-extras_sjs0.6_2.11 >> 0.3.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_sjs0.6_2.11 version0.3.0 in your project
Maven Dependency abc-extras_sjs0.6_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_sjs0.6_2.11 version0.2.1 in your project
Maven Dependency abc-laws_2.11 >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-laws_2.11 version0.2.0 in your project
Maven Dependency abc-laws_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-laws_2.11 version0.2.1 in your project
Maven Dependency abc-laws_sjs0.6_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-laws_sjs0.6_2.11 version0.2.1 in your project
Maven Dependency abc-laws_sjs0.6_2.11 >> 0.3.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-laws_sjs0.6_2.11 version0.3.0 in your project
Maven Dependency abc-collection_2.11 >> 0.3.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_2.11 version0.3.0 in your project
Maven Dependency abc-collection_2.12 >> 0.4.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_2.12 version0.4.0 in your project
Maven Dependency abc-collection_sjs0.6_2.11 >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_sjs0.6_2.11 version0.2.0 in your project
Maven Dependency abc-collection_sjs0.6_2.12 >> 0.4.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_sjs0.6_2.12 version0.4.0 in your project
Maven Dependency abc-extras_2.11 >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_2.11 version0.2.0 in your project

Ads