0% found this document useful (0 votes)
19 views3 pages

Tpcomp 001

Uploaded by

Amira Riham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Tpcomp 001

Uploaded by

Amira Riham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

package com.

company;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class Main extends JFrame implements ActionListener {

JPanel backgroundPanel;
JLabel label, labelResult, backgroundImage, titr;
JTextField textField;
JButton buttonFind;

public Main() {
createAndShowGUI();
}

public static void main(String[] args) {


SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {

new Main();
}
});
}

private void createAndShowGUI() {

backgroundPanel = new JPanel(null);


backgroundImage = new JLabel(new
ImageIcon(this.getClass().getResource("/images/tecno.jpg")));
label = new JLabel("Enter the sentence you want to convert here ",
JLabel.CENTER);
titr = new JLabel(" Compiler ");
textField = new JTextField();
buttonFind = new JButton("Conversion");
labelResult = new JLabel("", JLabel.CENTER);

backgroundPanel.setPreferredSize(new Dimension(553, 311));


backgroundImage.setBounds(0, 0, 553, 311);
titr.setBounds(20, 20, 400, 35);
label.setBounds(30, 60, 400, 30);
textField.setBounds(30, 90, 500, 50);
buttonFind.setBounds(180, 160, 200, 36);
labelResult.setBounds(0, 210, 553, 50);

label.setFont(new Font("Arial", Font.PLAIN, 20));


label.setForeground(Color.WHITE);

titr.setFont(new Font("Brush Script MT", Font.PLAIN , 40));


titr.setForeground(Color.yellow);

textField.setFont(new Font("Arial", Font.PLAIN, 18));


textField.setForeground(Color.LIGHT_GRAY);
textField.setBackground(new Color(10, 10, 10));
textField.setCaretColor(Color.WHITE);
textField.setFocusable(true);
textField.setBorder(BorderFactory.createCompoundBorder(
textField.getBorder(),
BorderFactory.createEmptyBorder(5, 5, 5, 5)));

buttonFind.setFont(new Font("Arial", Font.BOLD, 20));


buttonFind.setForeground(Color.LIGHT_GRAY);
buttonFind.setBackground(Color.DARK_GRAY);
buttonFind.setBorder(BorderFactory.createLineBorder(Color.GRAY, 2));
buttonFind.setFocusable(false);

labelResult.setFont(new Font("Arial", Font.PLAIN, 18));

backgroundPanel.add(label);
backgroundPanel.add(titr);
backgroundPanel.add(textField);
backgroundPanel.add(buttonFind);
backgroundPanel.add(labelResult);
backgroundPanel.add(labelResult);
backgroundPanel.add(backgroundImage);

buttonFind.addActionListener(this);

add(backgroundPanel);

setTitle("TPCompilation");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
pack();
setLocationRelativeTo(null);
setVisible(true);
}

@Override
public void actionPerformed(ActionEvent e) {

String s = textField.getText();
char[] sc= s.toCharArray();
char[] scc=new char[s.length()*2];
int i=0,j=0;
while (i<s.length()){
switch (sc[i]) {
case '(':
case ')':
case '*':
case '/':
case'%': scc[j] = sc[i]; scc[j+1]='#'; j+=2; i++; break;
case '+': if(sc[i+1] >= '0' && sc[i+1] <= '9'){
scc[j]=sc[i]; j++; i++;
}else {scc[j] = sc[i]; scc[j+1]='#'; j+=2; i++;} break;
case '-': if(sc[i+1] >= '0' && sc[i+1] <= '9'){
scc[j]=sc[i]; j++; i++;
}else {scc[j]=sc[i]; scc[j+1]='#'; j+=2; i++;} break;

default: if ( sc[i] == '.' || i==s.length()-1 || sc[i+1]==')' ||


sc[i+1]=='(' || sc[i+1]=='*' || sc[i+1]=='/' || sc[i+1]=='+' || sc[i+1]=='-' ||
sc[i+1]=='%' || sc[i+1]=='.'){
scc[j] = sc[i]; scc[j+1]='#'; j+=2; i++;
}else {scc[j]=sc[i]; j++; i++;}
}
}
i=0;
char[] scc2 =new char[j];
while (i < j){
scc2[i] = scc[i]; i++;
}
String ss=new String(scc2);
labelResult.setForeground(Color.green);
labelResult.setText(ss);

You might also like