用Java在GUI中进行蛋白质可视化

时间:2016-10-31 11:14:10

标签: java swing user-interface

我试图制作一个Java程序,向我展示氨基酸序列是极性/非极性的,以及它是极性的还是非极性的。

这是我到目前为止的代码:

def copy_relations(self, oldinstance):
    self.structure_to_exclude = oldinstance.structure_to_exclude.all()

这是第二类的代码:

package vink6;

import vink6.AAR.NotAnAA;
import java.awt.*;


public class AA extends javax.swing.JFrame {



    public AA() {
        initComponents();
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        Analyseer = new javax.swing.JButton();
        labelseq = new javax.swing.JLabel();
        text = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        panel = new javax.swing.JPanel();
        jlabel = new javax.swing.JLabel();
        label2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        Analyseer.setText("Analyseer");
        Analyseer.addActionListener(this::AnalyseerActionPerformed);

        labelseq.setText("Sequentie");

        text.setAutoscrolls(true);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        text.setViewportView(jTextArea1);

        javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
        panel.setLayout(panelLayout);
        panelLayout.setHorizontalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label2, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
                    .addComponent(jlabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        panelLayout.setVerticalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlabel, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addComponent(Analyseer, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addComponent(labelseq)
                        .addGap(18, 18, 18)
                        .addComponent(text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(28, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelseq)
                    .addComponent(text, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Analyseer, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        

    private void AnalyseerActionPerformed(java.awt.event.ActionEvent evt) {                                          
       if (evt.getSource() == Analyseer) {
        String inSeq = jTextArea1.getText().toUpperCase();
        System.out.println(inSeq);

        try{


        int PerA = AAR.Apolair(inSeq);
        System.out.println(PerA);

        int PerP = AAR.Polair(inSeq);
        System.out.println(PerP);

        int Totaal = PerA+PerP;

        int PercA = 100/Totaal*PerA;
        System.out.println(PercA);

        int PercP = 100/Totaal*PerP;
            System.out.println(PercP);

        Graphics paper = panel.getGraphics();        

        paper.clearRect(0, 0, 325, 102);
        paper.setColor(Color.MAGENTA);        
        paper.fillRect(0, 0, Math.round(PercP*3.25f), 50);
        paper.drawString("Polair: "+PercP+"%",Math.round(PercP*3.25f), 50);

        paper.setColor(Color.BLUE);
        paper.fillRect(0, 50, Math.round(PercA*3.25f), 50);
        paper.drawString("Apolair: "+PercA+"%", Math.round(PercA*3.25f), 100);
        }


        catch (NotAnAA err) {
            System.out.println("Dit is geen aminozuur");
        }
    }                                         

  }  
    public static void main(String args[]) {

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
*/
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AA.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        //</editor-fold>


        java.awt.EventQueue.invokeLater(() -> {
            new AA().setVisible(true);
        });
    }


    private javax.swing.JButton Analyseer;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JLabel jlabel;
    private javax.swing.JLabel label2;
    private javax.swing.JLabel labelseq;
    private javax.swing.JPanel panel;
    private javax.swing.JScrollPane text;

}

这是输出:

但是,我不希望这样的百分比,但我想要一个颜色的条,以及关于氨基酸的哪个部分是(非)极性的信息。像这样:

任何人都可以帮助我吗?

0 个答案:

没有答案