Создано демонстрационное приложение с графическим интерфейсом пользователя на основе разработанного/модифицированного лёгкого AWT-компонента и стандартных компонентов AWT. Данное приложение представляет из себя демонстрацию работы шифратора, где нажатие на кнопку имитирует подачу импульса на вход шифратора.
Last active
January 31, 2023 20:15
-
-
Save welel/04362474ce1134574043d9428ef57506 to your computer and use it in GitHub Desktop.
Simple GUI coder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.event.*; | |
import lbutton.LButton; | |
public class MyFrame extends Frame { | |
static MyFrame frame = new MyFrame(); | |
// Холст для рисования | |
static Canvas canvas; | |
static int font_size = 20; | |
// Кнопки соответствующие входам шифратора | |
static LButton n0 = new LButton("0"); | |
static LButton n1 = new LButton("1"); | |
static LButton n2 = new LButton("2"); | |
static LButton n3 = new LButton("3"); | |
static LButton n4 = new LButton("4"); | |
static LButton n5 = new LButton("5"); | |
static LButton n6 = new LButton("6"); | |
static LButton n7 = new LButton("7"); | |
static LButton n8 = new LButton("8"); | |
static LButton n9 = new LButton("9"); | |
// Переменные для хранения выходных сигналов шифратора | |
static int y1 = 0, y2 = 0, y3= 0, y4 = 0; | |
public static void main(String [] args) { | |
frame.setTitle("Example of Coder"); | |
frame.setSize(500,500); | |
frame.setBackground(new Color(128,20,50)); | |
n0.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
n1.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
n2.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
n3.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
n4.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
n5.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
n6.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
n7.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
n8.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
n9.setFont(new Font("TimesRoman", Font.PLAIN, font_size)); | |
// Создание панели для размещения кнопок | |
Panel panel = new Panel(new FlowLayout()); | |
// Добавление панели на верхнюю часть окна | |
frame.add(panel, BorderLayout.NORTH); | |
// Доваление кнопок на панель | |
panel.add(n0); | |
panel.add(n1); | |
panel.add(n2); | |
panel.add(n3); | |
panel.add(n4); | |
panel.add(n5); | |
panel.add(n6); | |
panel.add(n7); | |
panel.add(n8); | |
panel.add(n9); | |
// Регистрация блоков прослушивания с последующей реализацией приемников событий от кнопок | |
n0.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 0; y2 = 0; y3 = 0; y4 = 0; | |
canvas.repaint(); }}); | |
n1.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 0; y2 = 0; y3 = 0; y4 = 1; | |
canvas.repaint(); }}); | |
n2.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 0; y2 = 0; y3 = 1; y4 = 0; | |
canvas.repaint(); }}); | |
n3.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 0; y2 = 0; y3 = 1; y4 = 1; | |
canvas.repaint(); }}); | |
n4.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 0; y2 = 1; y3 = 0; y4 = 0; | |
canvas.repaint(); }}); | |
n5.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 0; y2 = 1; y3 = 0; y4 = 1; | |
canvas.repaint(); }}); | |
n6.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 0; y2 = 1; y3 = 1; y4 = 0; | |
canvas.repaint(); }}); | |
n7.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 0; y2 = 1; y3 = 1; y4 = 1; | |
canvas.repaint(); }}); | |
n8.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 1; y2 = 0; y3 = 0; y4 = 0; | |
canvas.repaint(); }}); | |
n9.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent ae) { | |
y1 = 1; y2 = 0; y3 = 0; y4 = 1; | |
canvas.repaint(); }}); | |
canvas = new Canvas() { | |
// Переопределение метода paint | |
public void paint(Graphics g) { | |
int x = n0.getX()+20; | |
int y = n0.getY(); | |
int delta = 0; | |
// Отрисовка рисунка шифратора | |
for ( int i = 0; i < 10; i++ ) { | |
g.drawLine(x+delta,0, x+delta, 100); | |
delta+=35; | |
} | |
g.drawRect(x-23,100, 360,100); | |
delta = 0; | |
for ( int i = 0; i < 4; i++ ) { | |
g.drawLine(30+x+delta, 100+100, 30+x+delta, 230); | |
delta+=87; | |
} | |
g.setFont(new Font("TimesRoman", Font.PLAIN, 100)); | |
g.setColor(Color.lightGray); | |
g.drawString("Coder", x+10 , y+180); | |
// Отрисовка выходных сигналов шифратора | |
g.setColor(Color.WHITE); | |
g.drawString(""+y1, x, y+310); | |
g.drawString(""+y2, x + 87, y+310); | |
g.drawString(""+y3, x + 87*2, y+310); | |
g.drawString(""+y4, x + 87*3, y+310); | |
} | |
}; | |
frame.add(canvas, BorderLayout.CENTER); | |
frame.setVisible(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment