0% found this document useful (0 votes)
22 views

Java

This document contains the code for a Java GUI application that displays information about internal combustion engines. It defines labels, text fields, combo boxes, and buttons to display and search engine characteristics. When buttons are clicked, it retrieves input from text fields and displays or searches the information.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Java

This document contains the code for a Java GUI application that displays information about internal combustion engines. It defines labels, text fields, combo boxes, and buttons to display and search engine characteristics. When buttons are clicked, it retrieves input from text fields and displays or searches the information.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this
template
*/
package com.mycompany.proiectjava;

import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

/**
*
* @author Nitro
*/
public class InterfataMotoTermica extends javax.swing.JFrame {

private javax.swing.JPanel detalii;


private JPanel panel;

/* Creates new form InterfataMasiniTermice


*/
public InterfataMotoTermica() {
initComponents();
}
/**
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jLabel1 = new javax.swing.JLabel();


jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox<>();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("MASINI TERMICE");
jLabel1.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
jLabel1.setText("CARACTERISTICI MASINI TERMICE");

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N


jLabel2.setText("Tip Motor");

jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N


jLabel3.setText("Tip Turbina");

jComboBox1.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N


jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]
{ "Mai multe", "Motor", "Scaune", "Jante", "Dotari Exterioare", "Dotari
Interioare", " " }));
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});

jButton1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N


jButton1.setText("Cautare");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel1Layout = new


javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 530, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 133, Short.MAX_VALUE)
);

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.Alignm
ent.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(119, 119, 119)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 272,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(53, 53, 53)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.Gr
oupLayout.Alignment.TRAILING, false)
.addComponent(jComboBox1,
javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(jLabel3,
javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.Gr
oupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.Co
mponentPlacement.RELATED)
.addComponent(jTextField2))
.addGroup(layout.createSequentialGroup()
.addGap(153, 153, 153)
.addComponent(jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE, 142,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE, 105,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(58, 58, 58)
.addComponent(jTextField1,
javax.swing.GroupLayout.PREFERRED_SIZE, 250,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jPanel1,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(76, 76, 76))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 41,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELAT
ED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE,
34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jTextField1)
.addGap(5, 5, 5)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.BASELINE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE,
34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2,
javax.swing.GroupLayout.PREFERRED_SIZE, 34,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELAT
ED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING, false)
.addComponent(jComboBox1,
javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1,
javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
.addGap(5, 5, 5)))
.addGap(26, 26, 26)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(19, Short.MAX_VALUE))
);

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

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:


jComboBox1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {


String selectedValue = (String) jComboBox1.getSelectedItem();
if ("Jante".equals(selectedValue) && !
isFrameOpen(InterfataJante.class)) {
new InterfataJante().setVisible(true);
}

if ("Dotari Exterioare".equals(selectedValue) && !


isFrameOpen(InterfataDotariExterioare.class)) {
new InterfataDotariExterioare().setVisible(true);
}

if ("Motor".equals(selectedValue) && !
isFrameOpen(InterfataMotor.class)) {
new InterfataMotor().setVisible(true);
}

}
});
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code her:e:


// JLabel label1=new JLabel("Tip Motor:");
// JTextField textField1=new JTextField(200);
// JLabel label2=new JLabel("model:");
// JTextField textField2=new JTextField(200);

String tipMotor=jTextField1.getText();
String model=jTextField2.getText();
// jPanel1.add(label1);
// jPanel1.add(textField1);
// jPanel1.add(label2);
// jPanel1.add(textField2);
afiseazaInformatii(tipMotor, model);

}
private void afisareMasina(String tipMotor, String model) {
setTitle("Afisare Moto Termica");
setSize(400, 300);

panel = new JPanel();


panel.setLayout(new GridLayout(0, 2));

afiseazaInformatii(tipMotor, model);
JScrollPane scrollPane=new JScrollPane(panel);
getContentPane().add(scrollPane);
setVisible(true);
}
private void afiseazaInformatii(String tipMotor, String model){

Motor[] vectorMotor = new Motor[10];


vectorMotor[0] = new Motor("Benzină", 150, 1998.0);
vectorMotor[1] = new Motor("Motorină", 120, 1598.5);
vectorMotor[2] = new Motor("Benzină", 180, 2499.9);
vectorMotor[3] = new Motor("Motorină", 110, 1399.7);
vectorMotor[4] = new Motor("Benzină", 200, 2999.0);
vectorMotor[5] = new Motor("Benzină", 170, 2299.5);
vectorMotor[6] = new Motor("Motorină", 130, 1699.3);
vectorMotor[7] = new Motor("Benzină", 190, 2599.8);
vectorMotor[8] = new Motor("Benzină", 220, 3499.2);
vectorMotor[9] = new Motor("Motorină", 140, 1799.6);

DotariExterioare[] vectorDotariExterioare = new DotariExterioare[10];


vectorDotariExterioare[0] = new DotariExterioare(true, "Rosu", true);
vectorDotariExterioare[1] = new DotariExterioare(false, "Albastru", false);
vectorDotariExterioare[2] = new DotariExterioare(true, "Verde", true);
vectorDotariExterioare[3] = new DotariExterioare(false, "Negru", false);
vectorDotariExterioare[4] = new DotariExterioare(true, "Gri", true);
vectorDotariExterioare[5] = new DotariExterioare(false, "Alb", false);
vectorDotariExterioare[6] = new DotariExterioare(true, "Portocaliu", true);
vectorDotariExterioare[7] = new DotariExterioare(false, "Galben", false);
vectorDotariExterioare[8] = new DotariExterioare(true, "Argintiu", true);
vectorDotariExterioare[9] = new DotariExterioare(false, "Auriu", false);

Jante[] vectorJante = new Jante[10];


vectorJante[0] = new Jante(8.0, 17.0, "Aliaj", 5);
vectorJante[1] =new Jante(7.5, 16.0, "Oțel", 4);
vectorJante[2] =new Jante(9.0, 18.0, "Aliaj", 6);
vectorJante[3] =new Jante(8.5, 19.0, "Aluminiu", 5);
vectorJante[4] =new Jante(7.0, 15.0, "Oțel", 4);
vectorJante[5] =new Jante(8.0, 18.0, "Aluminiu", 5);
vectorJante[6] =new Jante(7.5, 17.0, "Aliaj", 6);
vectorJante[7] =new Jante(8.5, 20.0, "Aliaj", 5);
vectorJante[8] =new Jante(7.0, 16.0, "Aluminiu", 4);
vectorJante[9] =new Jante(9.0, 19.0, "Aluminiu", 6);

motoTermica[] vectorMotoTermica = new motoTermica[10];


vectorMotoTermica[0] = new motoTermica("Zac","Sportster-Iron-883",
230,vectorMotor[0],vectorJante[0],vectorDotariExterioare[0]);
vectorMotoTermica[1] = new motoTermica("Radu","CBR1000RR-R-Fireblade-SP",
180,vectorMotor[1],vectorJante[1],vectorDotariExterioare[1]);
vectorMotoTermica[2] = new motoTermica("Zac","GSX-R1000",
300,vectorMotor[2],vectorJante[2],vectorDotariExterioare[2]);
vectorMotoTermica[3] = new motoTermica("Radu","Ninja-H2-SX-SE+",
260,vectorMotor[3],vectorJante[3],vectorDotariExterioare[3]);
vectorMotoTermica[4] = new motoTermica("Zac","Panigale-V4-
S",210,vectorMotor[4],vectorJante[4],vectorDotariExterioare[4]);
vectorMotoTermica[5] = new motoTermica("Radu","YZF-R1M",
190,vectorMotor[5],vectorJante[5],vectorDotariExterioare[5]);
vectorMotoTermica[6] = new motoTermica("Zac","S1000RR",
240,vectorMotor[6],vectorJante[6],vectorDotariExterioare[6]);
vectorMotoTermica[7] = new motoTermica("Radu","R1",
220,vectorMotor[7],vectorJante[7],vectorDotariExterioare[7]);
vectorMotoTermica[8] = new motoTermica("Zac","Diavel-1260-S",
240,vectorMotor[8],vectorJante[8],vectorDotariExterioare[8]);
vectorMotoTermica[9] = new motoTermica("Radu","Street-Triple-RS",
250,vectorMotor[9],vectorJante[9],vectorDotariExterioare[9]);

for(int i=0; i<vectorMotoTermica.length; i++){


if (vectorMotoTermica[i]!=null && "ardere
interna".equals(vectorMotoTermica[i].tipMotor) &&
"Model".equals(vectorMotoTermica[i].model)) {
{
JLabel label1=new JLabel("Model " + vectorMotoTermica[i].model);
JLabel label2=new JLabel("Marca " + vectorMotoTermica[i].marca);
JLabel label3=new JLabel("Km Parcursi " +
vectorMotoTermica[i].kmParcursi);
JLabel label4=new JLabel("Tip Motor " +
vectorMotoTermica[i].tipMotor);
JLabel label5 = new JLabel("Tip Turbina " +
vectorMotoTermica[i].model);
panel.add(label1);
panel.add(label2);
panel.add(label3);
panel.add(label4);
panel.add(label5);

}
}
panel.setVisible(true);
}
}

private boolean isFrameOpen(Class<?> frameClass) {


Frame[] frames = JFrame.getFrames();
for (Frame frame : frames) {
if (frameClass.isInstance(frame) && frame.isVisible()) {
return true;
}
}

return false;}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<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 ex) {

java.util.logging.Logger.getLogger(InterfataMasiniTermice.class.getName()).log(java
.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(InterfataMasiniTermice.class.getName()).log(java
.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(InterfataMasiniTermice.class.getName()).log(java
.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(InterfataMasiniTermice.class.getName()).log(java
.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new InterfataMotoTermica().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton jButton1;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration
}

You might also like